几秒钟后停用 UILongPressGestureRecognizer? [关闭]
Posted
技术标签:
【中文标题】几秒钟后停用 UILongPressGestureRecognizer? [关闭]【英文标题】:Deactivate UILongPressGestureRecognizer after certain seconds? [closed] 【发布时间】:2016-02-17 05:49:02 【问题描述】:如何在几秒钟后自动停用我的 UILongPressGestureRecognizer?
【问题讨论】:
【参考方案1】:在 -viewDidLoad 中设置时间间隔:
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(removeGesture) userInfo:nil repeats:NO];
在选择器方法中:
-(void)removeGesture
[self.view removeGestureRecognizer:longGesture1];
5 秒后,UILongPressGestureRecognizer 从视图中移除并停用
【讨论】:
【参考方案2】:检查一下:
[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];
希望这会有所帮助。
【讨论】:
以上是关于几秒钟后停用 UILongPressGestureRecognizer? [关闭]的主要内容,如果未能解决你的问题,请参考以下文章