我想添加一个手势,只有当一个人已经按下一秒钟左右才会触发。不是轻拍,而是长按。如果我使用uilongpressgesturerecognizer它会持续发射,直到我释放我的手指。我怎样才能解决这个问题。uilongpressgesturerecognizer只触发一次
3
A
回答
5
设置,当你创建并添加手势如下minimumPressDuration
-(void)handleLongPress:(UILongPressGestureRecognizer *)Gesture{
if (Gesture.state == UIGestureRecognizerStateEnded) {
//Do any thing after long press ended,which will be 1.0 second as set above
}
else if (Gesture.state == UIGestureRecognizerStateBegan){
}
}
+0
谢谢像魅力一样工作。 – TheHellOTrofasdasd
0
设定值minimumPressDuration
财产UILongPressGestureRecognizer
。
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.0;
编写代码在UIGestureRecognizerStateEnded
状态如下:
0
当按钮状态改变,长按方法被调用一次(开始,结束) 如果你想实现的东西,那么做如下。
//MARK:Button tap events
- (void)btnLongPress:(UILongPressGestureRecognizer*)gesture{
switch (gesture.state) {
case UIGestureRecognizerStateBegan:
{
//tmrForPoint is timer
tmrForPoint = [NSTimer timerWithTimeInterval:0.5 target:self selector:@selector(btnAddTap) userInfo:nil repeats:YES];
NSRunLoop * theRunLoop = [NSRunLoop mainRunLoop];
[theRunLoop addTimer:tmrForPoint forMode:NSDefaultRunLoopMode];
}
break;
case UIGestureRecognizerStateEnded:
{
[tmrForPoint invalidate];
tmrForPoint = nil;
}
break;
default:
break;
}
}
//Call this method every 0.5 Second
-(void)btnAddTap{
NSLog("Method called")
}
相关问题
- 1. UILongPressGestureRecognizer只调用第二次
- 2. Excel.Application.SelectionChange只触发一次
- 3. WPF:PropertyChangedCallback只触发一次
- 4. UIDeviceOrientationDidChangeNotification只会触发一次
- 5. BroadcastReceiver只触发一次
- 6. backgroundworker只触发一次
- 7. javascript oninput只触发一次?
- 8. System.Threading.Timer只会触发一次
- 9. 角度事件只能触发一次触发一次
- 10. 让jquery ajaxStop每次只触发一次
- 11. UILongPressGestureRecognizer开始后的第二次触摸
- 12. jQuery如何让一个事件触发一次只触发一次div
- 13. .on('animationend webkitAnimationEnd oAnimationEnd')只会触发一次
- 14. javafx谓词只有第一次触发
- 15. Jquery Mobile按钮只触发一次
- 16. $范围$只腕表触发一次
- 17. jquery函数只触发一次
- 18. 虽然只有一次触发
- 19. FilesystemWatcher只触发一次事件
- 20. 使c#/ wpf事件只触发一次?
- 21. WPF动画只触发一次
- 22. ValueEventListener触发onDataChange方法只需一次
- 23. 为什么jQuery .after()只触发一次?
- 24. Page_Load事件只会触发一次
- 25. 点击只能触发一次
- 26. NeedDataSource和ItemDataBinding只触发一次
- 27. 的Javascript的addEventListener只触发一次
- 28. JavaScript更改函数只触发一次
- 29. jQuery代码只触发一次
- 30. WebClient的DownloadStringCompleted只能触发一次
你用什么样的姿势来看这个?如果您打开'gestureRecognizer.state'并只查找'.Ended'状态,那么每长按一次(长按结束时)将只发生一次。 – keithbhunter