你可以設置一個名爲「lastPoint」的成員變量來記錄點你感動
的,你可以calc下下一次的方向
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.
}
我沒仔細看過那個帖子最後一次,但我注意到接受的答案計算了fromAngle和toAngle。這些差異的跡象似乎是你需要的。 – danh 2012-04-18 00:48:55
這不起作用。在一個圓圈內,你不能依靠角度來看物體旋轉的方向,這意味着如果我將物體從270度旋轉到270度,我怎麼知道我旋轉物體的方式? – 2012-04-18 01:24:58