私はタッチで円の矢印を回転させる必要があるiPadアプリに取り組んでいます。しかし、私はその中で問題に直面しています。問題は、画像を回転させる角度の計算にあります。
ここで確認できます。大きな赤い矢印の画像を円の周りに回転させる必要があります。タッチポイントの角度を取得する方法を教えてください。現在、次のコードを使用しています。ネットのどこかで見つけました。しかし、タッチした場所に矢印が回転しませんでした。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *oneTouch = [touches anyObject];
CGPoint currentPoint = [oneTouch locationInView:imgCompass];
double current_angle = [self wheelAngleFromPoint:currentPoint];
imgNeedle.transform = CGAffineTransformMakeRotation( current_angle );
}
- (double) wheelAngleFromPoint:(CGPoint)location
{
double retAngle;
// subtract center of wheel
location.x -= (self.imgNeedle.bounds.size.width ) / 2.0;
location.y = (self.imgNeedle.bounds.size.height ) / 2.0 - location.y;
// normalize vector
double vector_length = sqrt(location.x*location.x + location.y*location.y);
location.x = location.x/vector_length;
location.y = location.y/vector_length;
retAngle = acos(location.y);
float offset = 0.28;
//if (location.x)
// offset = 0.28;
retAngle += offset;
if (location.x<0)
{
retAngle = -retAngle;
}
return retAngle;
}
誰でも正しい角度の計算を手伝ってくれますか?
ありがとう