码迷,mamicode.com
首页 > 其他好文 > 详细

立即响应ScrollView上的子视图的手势

时间:2016-03-15 12:12:44      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

 

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是否需要滚动。

立即响应ScrollView上的子视图的手势

标签:

原文地址:http://www.cnblogs.com/-yun/p/5278785.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!