I have a button, and I want to "press down and hold" the button so it will keep printing "Long Press" until I release the key press.
I have this in the ViewDidLoad:
[self.btn addTarget:self action:@selector(longPress:) forControlEvents:UIControlEventTouchDown];
and
- (void)longPress: (UILongPressGestureRecognizer *)sender {
if (sender.state == UIControlEventTouchDown) {
NSLog(@"Long Press!");
}
}
I have also tried this:
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
lpgr.minimumPressDuration = 0.1;
lpgr.numberOfTouchesRequired = 1;
[self.btn addGestureRecognizer:lpgr];
It only prints out Long Press! once even when I hold down the button. Can anyone tell me where I did wrong or what I missed? Thanks!