检测iOS中PAN姿势的方向 [英] Detecting the direction of PAN gesture in iOS
问题描述
在我的应用程序中有一个图像view.Im添加PAN姿势到该图像视图。
In my app there is a image view.Im adding PAN gesture to that image view.
这很好。
图片视图处于横向模式。
The image view is in landscape mode.
我想在用户平移到正确方向时增加标签的计数,向左方向。
I want to increase a count in label while user pan to right direction and decrease that count while user pan to left direction.
我搜索了很多,但没有找到解决方案。
I googled a lot but didn't find a solution for this.
请帮助我如何检测用户正在平移的方向(左/右)?
Can anyone please help me how to detect the direction in which the user is panning(left/right)?
推荐答案
您的手势识别器,使用 - (CGPoint)velocityInView:(UIView *)view;
:
In the target selector of your gesture recognizer, use - (CGPoint)velocityInView:(UIView *)view;
:
- (void)panRecognized:(UIPanGestureRecognizer *)rec
{
CGPoint vel = [rec velocityInView:self.view];
if (vel.x > 0)
{
// user dragged towards the right
counter++;
}
else
{
// user dragged towards the left
counter--;
}
}
Ps:我不知道这个方法,直到约。 3分钟前。谷歌的第一个点击是苹果的官方文档。
P.s.: I didn't know about this method until approx. 3 minutes before. One of Google's first hits was the official Apple documentation.
这篇关于检测iOS中PAN姿势的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!