将滚动事件从uibutton传递到uiscrollview
我有水平UIScrollView
从UIScrollView
延伸,我水平添加UIButtons
。 我只能滚动出按钮区域,但如果我想滚动任何按钮是触发UIControlEventTouchUpInside
事件。 我不想要这个。 我想点击UIControlEventTouchUpInside
动作,如果我点击,我想滚动,如果我滚动。
所以我怎么可以将滚动事件从UIButton
传递给UIScrollView
?
子类UIScrollView,在- touchesShouldCancelInContentView:
方法中返回YES。
该功能已内置。当您将UIControl元素作为滚动视图的子视图并检测到触摸事件时,它最初会传递给UIScrollView。 如果在一两秒之后触摸事件中没有足够的移动,它会传递给按钮。
如果你继承了NSButton类并且创建了你的类型的按钮并且在你的子类中覆盖了以下内容,你可以将事件传递回父视图,在你的情况下,滚动视图
以下内容会使按钮从不触发事件,而是全部由父视图处理:
- (void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event {
[self.nextResponder touchesBegan:touches withEvent:event];
}
- (void)touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event {
[self.nextResponder touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event
{
[self.nextResponder touchesEnded:touches withEvent:event];
}
如果你想让按钮处理这些事件之一,而不是使用
[super touchesEnded:touches withEvent:event];
链接地址: http://www.djcxy.com/p/40519.html