In my app I want the UILongPressGestureRecognizer will send continuous messages every second until the button is released. Unfortunately there is no state like "continuous" so I need to use "began" and "ended" to control my messages. Here is my code I have so far, I get both logs on the terminal but the while loop is not stopping?
- (void)longPress:(UILongPressGestureRecognizer*)gesture {
BOOL loop = NO;
if (gesture.state == UIGestureRecognizerStateBegan) {
NSLog(@"Long press detected.");
loop = YES;
while (loop){
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
// here I want to do my stuff every second
}
} else if (gesture.state == UIGestureRecognizerStateEnded) {
NSLog(@"Long press Ended");
loop = NO;
}
}
Does anyone please can help?