UILongPressGestureRecognizer 的兩次觸發


當你使用longPress gesture recognizer 時,你可能會發現調用了多次。

 

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizeralloc] initWithTarget:selfaction:@selector(longPress:)];

    longPress.delegate = self;

    [self.viewaddGestureRecognizer:longPress];

其實時因為響應不同的狀態。所以,要在你的方法里加上狀態的判斷。可以看到,開始響應,結束響應,如果你不判斷的話,都會調用你的方法。

-(void)longPress:(UILongPressGestureRecognizer *)sender

{

    if (sender.state == UIGestureRecognizerStateBegan) {

        [self yourMethod];

    }

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM