zoukankan      html  css  js  c++  java
  • 立即响应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是否需要滚动。

    让明天,不后悔今天的所作所为
  • 相关阅读:
    服务器文档下载zip格式
    关于精度,模运算和高精的问题//19/07/14
    Luogu P2010 回文日期 // 暴力
    树形DP水题集合 6/18
    普通背包水题集合 2019/6/17
    因为时间少
    重学树状数组6/14(P3368 【模板】树状数组 2)
    Luogu P1291 [SHOI2002]百事世界杯之旅 // 易错的期望
    Luogu P4316 绿豆蛙的归宿//期望
    树剖
  • 原文地址:https://www.cnblogs.com/-yun/p/5278785.html
Copyright © 2011-2022 走看看