立即响应ScrollView上的子视图的手势
self.myScrollView.delaysContentTouches = YES;
self.myScrollView.CanCancelContentTouches=NO;
写了一个继承scrollview的类,并在里面实现了touch事件,但是如果要相应touch事件,必须要先让手指在scrollview上停留一会,否则,手指一滑动,直接进scroll的事件了,根本不会触发touch事件。
下面是我在scrollview里面重写的touch事件,那几个NSLog如果手指不停留,更本就不会触发!
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"PageScrollView Touch begin");
if(!self.dragging)
{
[[self nextResponder] touchesBegan:touches withEvent:event];
}
[super touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"PageScrollView Touch Move");
if(!self.dragging)
{
[[self nextResponder] touchesMoved:touches withEvent:event];
}
[super touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"PageScrollView Touch End");
if(!self.dragging)
{
[[self nextResponder] touchesEnded:touches withEvent:event];
}
[super touchesEnded:touches withEvent:event];
}
具体地实现有所不同,需要先将delaysContentTouches设 置为NO,CanCancelContentTouches设置为YES,而后使用- (BOOL)touchesShouldCancelInContentView:(UIView *)view来决定scrollview是否需要滚动。
posted on 2016-03-15 11:50 Sinner_Yun 阅读(402) 评论(0) 编辑 收藏 举报