我有一个按钮,我想“按住”按钮,这样它将继续打印“长按”,直到我释放按键。
我在 ViewDidLoad 中有这个:
[self.btn addTarget:self action:@selector(longPress:) forControlEvents:UIControlEventTouchDown];
和
- (void)longPress: (UILongPressGestureRecognizer *)sender {
if (sender.state == UIControlEventTouchDown) {
NSLog(@"Long Press!");
}
}
我也试过这个:
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
lpgr.minimumPressDuration = 0.1;
lpgr.numberOfTouchesRequired = 1;
[self.btn addGestureRecognizer:lpgr];
它只打印出长按!即使我按住按钮一次。谁能告诉我哪里做错了或者我错过了什么?谢谢!