mor*_*tar 26 iphone touch uiscrollview viewcontroller nsresponder
我在视图控制器(UIViewController的自定义子类)中处理了几个我的UI组件.它的方法touchesBegan:withEvent:
,touchesMoved:withEvent:
和touchesEnded:withEvent:
.它工作正常.然后我添加了一个滚动视图(UIScrollView)作为层次结构中的顶视图.
现在我在视图控制器上的触摸处理程序不起作用.他们没有被召唤.有趣的是,我在滚动视图中有各种其他UI组件可以正常工作.有些是按钮,有些是定义自己的自定义视图touchesBegan:withEvent:
等.唯一不起作用的是视图控制器上的触摸处理程序.
我想也许是因为滚动视图拦截为己用的触动,但我UIScrollView的子类,只是看看,如果我能得到它的工作,我回来YES
总是touchesShouldBegin:withEvent:inContentView:
和NO
来自始终touchesShouldCancelInContentView:
.仍然无法正常工作.
如果它有所作为我的视图控制器在标签栏控制器内,但我不认为它是相关的.
有没有人有这个问题并有一个现成的解决方案?我的猜测是滚动视图猴子响应者链.我可以回来吗?我想如果我无法想出任何其他内容,我会将滚动视图下的顶级视图设为自定义视图,并将消息转发给视图控制器,但看起来很糟糕.
use*_*093 22
创建UIScrollView类的子类并覆盖touchesBegan:和其他触摸方法,如下所示:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
// If not dragging, send event to next responder
if (!self.dragging){
[self.nextResponder touchesBegan: touches withEvent:event];
}
else{
[super touchesBegan: touches withEvent: event];
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
// If not dragging, send event to next responder
if (!self.dragging){
[self.nextResponder touchesMoved: touches withEvent:event];
}
else{
[super touchesMoved: touches withEvent: event];
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
// If not dragging, send event to next responder
if (!self.dragging){
[self.nextResponder touchesEnded: touches withEvent:event];
}
else{
[super touchesEnded: touches withEvent: event];
}
}
Run Code Online (Sandbox Code Playgroud)
“它工作得很好。然后我添加了一个滚动视图 (UIScrollView) 作为层次结构中的顶部视图。”
您的滚动视图是否位于包含项目的内容视图之上?
所有组件都应该位于滚动视图中,而不是位于滚动视图后面的视图中