如何减慢UIPanGestureRecognizer的速度?
我有一个方法,当识别到 2 指平移手势时,我想调用该方法。我已经设置好并且工作正常,但问题是我只需要大约 15 次调用该方法(它过滤图像),当我平移大约一英寸时,该方法已被调用一百遍,图像转得如此之快,我不知道发生了什么。
我该怎么做才能减慢手势识别器的速度?
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:2];
[panRecognizer setMaximumNumberOfTouches:2];
[panRecognizer setDelegate:self];
[self view] addGestureRecognizer:panRecognizer]];
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]];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
想必您每次收到平移事件时都会更改图像。这不太好。相反,您应该向平移手势识别器询问拖动距离(使用
-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.我创建了一个“responseCount”,基本上捕获每第四个或第五个(有效)手势。
I created a "responseCount" basically capturing every 4th or 5th (valid) gesture.
斯威夫特4
Swift 4