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

    让明天,不后悔今天的所作所为
  • 相关阅读:
    二叉树遍历
    NO.35 2021/12/13(06:50)[周一]
    NO.29 2021/11/30(06:30)[周二]
    NO.22 2021/11/19(06:15) [周五]
    The .NET ORM Architec
    C#格式字符串
    C# Attribute
    .net DLL反编译文件
    【Beta】Scrum meeting1
    【Alpha】Scrum meeting 6
  • 原文地址:https://www.cnblogs.com/-yun/p/5278785.html
Copyright © 2011-2022 走看看