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

    让明天,不后悔今天的所作所为
  • 相关阅读:
    备战noip week1
    20200820校测
    UVA 11419 SAM I AM
    需求沟通技巧
    ReentrantLock和ReentrantReadWriteLock对比
    线程池浅析
    常用设计模式之单例模式
    java开发3~5年工作经验面试题
    2019计划
    Linux系统安装Tomcat
  • 原文地址:https://www.cnblogs.com/-yun/p/5278785.html
Copyright © 2011-2022 走看看