如何在几秒钟后自动停用我的UILongPressGestureRecognizer?
答案 0 :(得分:0)
在-viewDidLoad中设置时间间隔:
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(removeGesture) userInfo:nil repeats:NO];
选择器方法中的:
-(void)removeGesture
{
[self.view removeGestureRecognizer:longGesture1];
}
5秒钟后,UILongPressGestureRecognizer从视图中移除并将停用
答案 1 :(得分:0)
检查一下:
[self performSelector:@selector(onTick:) withObject:nil afterDelay:2.0/*your delay time*/];
-(void)onTick:(id)sender
{
for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers) {
if([recognizer isKindOfClass:[UILongPressGestureRecognizer class]]) {
[self removeGestureRecognizer:recognizer];
}
}
}
希望这有帮助。