美文网首页iOS开发资料收集区
iOS手势:正常滑动时,一直调用- (void)touchesC

iOS手势:正常滑动时,一直调用- (void)touchesC

作者: hu9134 | 来源:发表于2016-12-14 10:57 被阅读876次

    问题:

    使用iOS手势,按照正常来说,应该是首先调用了touchesbegain,结束时调用touchesend,只有发生系统事件时,才会调用touchesCancel,但是遇到一个问题就是,一直最开始就调用touchescancel,执行不到touchesend,所以调用不了方法.

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
    - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
    - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
    - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
    

    解决办法:

    UIGestureRecognizer

    有一个cancelsTouchesInView属性

    cancelsTouchesInView
    —If a gesture recognizer recognizes its gesture, it unbinds the remaining touches of that gesture from their view (so the window won’t deliver them). The window cancels the previously delivered touches with a (touchesCancelled(_:with:)
    ) message. If a gesture recognizer doesn’t recognize its gesture, the view receives all touches in the multi-touch sequence.

    查找资料过程中还发现一个问题

    Note: touches also get cancelled if you start a UIView
    animation after touchesBegan

    . To prevent this make sure you include UIViewAnimationOptionAllowUserInteraction:

    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ self.aView.hidden = NO; self.aView.alpha = 1; } completion:nil];
    
    

    可以参考一下!

    相关文章

      网友评论

        本文标题:iOS手势:正常滑动时,一直调用- (void)touchesC

        本文链接:https://www.haomeiwen.com/subject/eulimttx.html