zoukankan      html  css  js  c++  java
  • UILongPressGestureRecognizer的selector多次调用解决方法

    当你使用longPress gesture recognizer 时,你可能会发现调用了多次。

    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
    
    longPress.delegate = self;
    
    [self.view addGestureRecognizer:longPress];
    

    其实时因为响应不同的状态。所以,要在你的方法里加上状态的判断。可以看到,开始响应,结束响应,如果你不判断的话,都会调用你的方法。

    - (void)longPress:(UILongPressGestureRecognizer *)sender {
    
        if (sender.state == UIGestureRecognizerStateBegan) {
        
             [self yourMethod];
    
        }
    
    }
    
  • 相关阅读:
    Nginx配置文件
    SSM三层模型之间的参数传递
    Junit4用法
    常量类的设计
    初识Oracle
    sss
    sss
    sss
    sss
    sss
  • 原文地址:https://www.cnblogs.com/LeeYZ/p/5037722.html
Copyright © 2011-2022 走看看