I wanted to detect the user touch release and if the user is holding it, the code down below
works, but dont tell me if i’m holding ( touch and hold and not releasing ) the touch…
please help me fix that
[imageview setUserInteractionEnabled:YES];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(holdAction:)];
[singleTap setNumberOfTapsRequired:1];
[imageview addGestureRecognizer:singleTap];
- (void)holdAction:(UIGestureRecognizer *)holdRecognizer
{
if (holdRecognizer.state == UIGestureRecognizerStateBegan) {
NSLog(@"Holding Correctly. Release when ready.");
} else if (holdRecognizer.state == UIGestureRecognizerStateEnded)
{
NSLog(@"You let go!");
}
}
Do it with the
-touchesBegan:withEvent:and-touchesEnded:withEvent:methods.Where self.isHolding is a
@property (nonatomic, assign) BOOL isHolding;Note: In those methods you may need to perform additional check if the touches have started over a particular view and also where they have ended.
UPDATE: Change your code accordingly: