我已经使用本文中的这段代码成功实现了旋转uiimageview

iPhone - Wheel tracking finger jumps to same starting position?

我对其他开发人员的问题是,触摸的用户可以顺时针和逆时针旋转图像。有什么方法可以检测用户向哪个方向移动视图?

这对我很重要,因为我正在制作时钟应用程序。我让用户将最小指针从0分钟一直移动到60分钟。当到达那儿时,我将时针向上移一个。但是用户可以逆时针旋转分针,在这种情况下,我需要将时针向下移动一个。有任何想法吗?

最佳答案

您可以设置一个名为“ lastPoint”的成员变量来记录上次移动的点

你下次可以计算方向


CGPoint lastPoint;


- (void) touchedBegin:(NSSet *)touches withEvent:(UIEvent *)event {
    lastPoint = [touch locationInView:self.view];
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];

//you can save the point , then used in next time you want

int tInput = [allTouches count]-1;

UITouch *touch =[[allTouches allObjects] objectAtIndex:tInput];
CGPoint location = [touch locationInView:self.view];
float theAngle = atan2( location.y-imageX.center.y, location.x-imageX.center.x );

float theLastAngle =  atan2( lastPoint.y-imageX.center.y, lastPoint.x-imageX.center.x );

lastPoint = location;

// compare theAngle & theLastAngle , so you can know it is clockwise or counterclockwise.
}

关于iphone - UIImageView如何跟踪顺时针或逆时针的用户运动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10201048/

10-11 11:01