如何减慢UIPanGestureRecognizer的速度? [英] How to slow down the speed of UIPanGestureRecognizer?
问题描述
我有一个方法,当识别出两根手指的平移手势时,我想调用该方法.我已经设置好并且可以正常工作,但是问题是只有大约15次需要调用该方法(它会过滤图像),而当我平移大约一英寸时,该方法已被调用一百次,图像拍得太快了,我不知道发生了什么.
I have a method that I would like to call when a 2 finger pan gesture is recognized. I have it setup and working ok, but the problem is that there is only about 15 times I need the method to be called (it filters through images), and by the time I've panned about an inch, the method has been called a hundred times and the images went by so fast I didn't know what was going on.
我该怎么做以减慢我的手势识别器?
What can I do to slow down my gesture recognizer?
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:2];
[panRecognizer setMaximumNumberOfTouches:2];
[panRecognizer setDelegate:self];
[self view] addGestureRecognizer:panRecognizer]];
推荐答案
大概是每次发生pan事件时您都在更改图像.那不是很好.相反,您应该询问平移手势识别器的拖动距离(使用-translationInView:
),并且只有在超过特定阈值后才更改图像.
Presumably you're changing images every time you get a pan event. That's not very good. Instead you should ask the pan gesture recognizer for the drag distance (use -translationInView:
) and only change images once you've passed a specific threshold.
这篇关于如何减慢UIPanGestureRecognizer的速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!