UILongPressGestureRecognizer 的两次触发

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

 

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizerallocinitWithTarget:selfaction:@selector(longPress:)];get

    longPress.delegate = self;it

    [self.viewaddGestureRecognizer:longPress];io

其实时由于响应不一样的状态。因此,要在你的方法里加上状态的判断。能够看到,开始响应,结束响应,若是你不判断的话,都会调用你的方法。select

-(void)longPress:(UILongPressGestureRecognizer *)sender方法

{view

    if (sender.state == UIGestureRecognizerStateBegan) {vi

        [self yourMethod];co

    }void

}

找了好久,才找到这么解释得简洁明了的文章,文章写得很好

相关文章
相关标签/搜索