美文网首页
UILongPressGestureRecognizer 的两次

UILongPressGestureRecognizer 的两次

作者: 啷里个啷里个啷个里个啷 | 来源:发表于2017-02-20 14:19 被阅读0次

当你使用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];

    }

}

相关文章

网友评论

      本文标题:UILongPressGestureRecognizer 的两次

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