【发布时间】:2011-02-11 09:19:04
【问题描述】:
UIScrollView 编程对我来说似乎是最困难的任务之一 :(
我在 UIScrollView 中有子视图。
我想让子视图首先获取触摸事件(并被拖动)。
当子视图认为它应该放弃触摸并开始滚动时,它应该能够告诉滚动视图。
我已经尝试过 touchesShouldCancelInContentView,但是当 scrollView 认为用户实际上想要“滚动”时,这个方法只会被调用一次。
我需要控制何时取消子视图的触摸事件,而不依赖于内部 uiscrollview 的实现。
到目前为止我最好的策略是
子类 ScrollView
- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
{
SYSLOG(LOG_DEBUG, "MyScrollView touchesBegan");
if (!self.dragging && self.isSubviewTouchable)
[self.nextResponder touchesBegan: touches withEvent:event];
[super touchesBegan: touches withEvent: event];
}
从scrollView的子视图
当subview需要释放触摸,让scrollView去接受触摸事件等等。
self.myScrollView.isSubviewTouchable = false;
[self touchesEnded: touches withEvent: event];
在 scrollView 的委托类中,我将 bool 值设置回来。
- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
self.myScrollView.isSubviewTouchable = true;
}
问题是,从子视图调用 touchesEnded 实际上并没有释放它看起来的触摸事件。(即使在 touchesEnded 调用之后子视图仍然被拖动) 此外,在我希望的 touchesEnded 调用之后,我没有看到 scrollView 获得任何触摸事件。
有什么想法吗?
谢谢
【问题讨论】:
标签: iphone uiscrollview touch