我已经使用此帖子中的代码成功实现了旋转uiimageview
iPhone - Wheel tracking finger jumps to same starting position?
我向其他开发人员提出的问题是,触摸用户可以顺时针和逆时针旋转图像。有没有办法可以检测用户移动视图的方向?
对我来说很重要,因为我正在制作一个时钟应用程序。我让用户将最小手形从0分钟一直移动到60分钟。当它到达那里时,我将时针向上移动一下。但是用户可以逆时针旋转最小手,在这种情况下我需要将时针向下移动一下。有什么想法吗?
答案 0 :(得分:3)
您可以设置名为“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.
}