开发者

UIGestureRecognizer tap and remove

开发者 https://www.devze.com 2023-04-02 16:52 出处:网络
I have a UILongPressGestureRecognizer that fires the method -(void)didPress. The current view has by default a UIImage. didPress makes the UIImage disappear off the screen. However, the image should o

I have a UILongPressGestureRecognizer that fires the method -(void)didPress. The current view has by default a UIImage. didPress makes the UIImage disappear off the screen. However, the image should only disappear off the screen as long as the user is still long pressing. Once the user lets go of the initial long press, the image reappears. I have the code already to handl开发者_运维百科e the initial long press, but I'm not sure how to determine when the user has let go of that long touch.


You should pass the UILongPressGestureRecognizer to your method and check the state of the gesture, when the user releases his finger/fingers out of the screen, it will send a state of UIGestureRecognizerStateEnded

- (void)didPress:(UILongPressGestureRecognizer *)recognizer {
   if (recognizer.state == UIGestureRecognizerStateBegan) {
     NSLog(@"Started");
   }
   if (recognizer.state == UIGestureRecognizerStateEnded) {
     NSLog(@"Finished");    
   }
}

Using touchesBegan:withEvent: is old and way before UIGestureRecognizer's

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号