大佬教程收集整理的这篇文章主要介绍了iOS:如何获得长按手势的持续时间?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
[gameObjectView addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@SELEctor(handle:)]];
然后处理函数
- (void)handle:(UILongPressGestureRecognizer)gesture { if (gesture.state == UIGestureRecognizerStateEnded) { // Get the duration of the gesture and calculate the value for the attribute } }
在这种情况下,如何获得长按手势的持续时间?
ios 5(未经测试)的解决方法:
创建一个名为timer的NSTimer属性:@property(nonatomic,strong)NSTimer * timer;
还有一个柜台:@property(nonatomic,strong)int counter;
然后@synthesize
- (void)incrementCounter { self.counter++; } - (void)handle:(UILongPressGestureRecognizer)gesture { if (gesture.state == UIGestureRecognizerStateBegan) { self.counter = 0; self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self SELEctor:@SELEctor(incrementCounter) userInfo:nil repeats:yes]; } if (gesture.state == UIGestureRecognizerStateEnded) { [self.timer invalidate]; } }
所以当手势开始启动一个每秒钟触发递增方法的定时器,直到手势结束.在这种情况下,您将要将minimumPressDuration设置为0,否则手势将不会立即开始.然后做任何你想要的柜台!
以上是大佬教程为你收集整理的iOS:如何获得长按手势的持续时间?全部内容,希望文章能够帮你解决iOS:如何获得长按手势的持续时间?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。