0

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

iPhone - 车轮跟踪手指跳到相同的起始位置?

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

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

4

1 回答 1

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.
}

于 2012-04-18T01:47:38.113 回答