以下は、タッチイベントで矢印(uiimage)を回転させるためのコードです。これで、前と現在の2つのタッチの位置を差し引きますが、問題は、矢印(uiimage)がタッチの反対方向に移動することがあることです。
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch *touch = [touches anyObject];
NSLog(@"%@",[touch view]);
if ([touch view] == ImgViewArrowImage)
{
CGPoint currentLocation = [touch locationInView:touch.view];
CGPoint pastLocation = [touch previousLocationInView:touch.view];
CGPoint d1 = CGPointMake(currentLocation.x-touch.view.center.x, currentLocation.y-touch.view.center.y);
CGPoint d2 = CGPointMake(pastLocation.x-touch.view.center.x, pastLocation.y-touch.view.center.y);
CGFloat angle1 = atan2(d1.y, d1.x);
CGFloat angle2 = atan2(d2.y, d2.x);
[[ImgViewArrowImage layer] setAnchorPoint:CGPointMake(0.0, 0.5)];
[[ImgViewArrowImage layer] setPosition:CGPointMake(159,211)];
ImgViewArrowImage.transform = CGAffineTransformRotate(ImgViewArrowImage.transform, angle1-angle2);
}
}