3

の画面の軸について、vectorから取得しようとしています。戦闘の半分である速度を取得できることはわかっていますが、理想的には、画面の垂直軸を中心とした角度(コンパス度またはラジアン)を取得する手段が必要です。たとえば、左下から右上へのドラッグは45度の角度、上から下へのドラッグは180度、または下から上へのドラッグは0(または360)になります。UIPanGestureRecognizerPortrait Orientation

これは可能ですか?これにはdirectionプロパティがなく、ドキュメントでの翻訳の説明は少しわかりにくいです。手動で(ビューの中心付近に)中心点を作成し、の開始点/終了点をそれと比較する必要がありPan Touchますか?必要な数学が少しわかりません。

前もって感謝します!^ _ ^

4

2 に答える 2

6

あなたが速度を得ることができるならば:

CGPoint velocity = [recognizer velocityInView:self.view]

次に、x軸に対する角度を次のように計算できます。

float x = velocity.x;
float y = velocity.y;

double angle = atan2(y, x) * 180.0f / 3.14159f;
if (angle < 0) angle += 360.0f; 
于 2013-01-14T13:14:49.690 に答える
0
CGPoint startLocation = [sender locationInView:self.view];
if (sender.state == UIGestureRecognizerStateBegan) {
     startLocation = [sender locationInView:self.view];
}
else if (sender.state == UIGestureRecognizerStateEnded) {
     CGPoint stopLocation = [sender locationInView:self.view];
     CGFloat dx = stopLocation.x - startLocation.x;
     CGFloat dy = stopLocation.y - startLocation.y;

     double angle = atan2(dy, dx) * 180.0f / M_PI;
     if (angle < 0) angle += 360.0f;
     NSLog(@"angle: %f",angle);
}
于 2015-03-11T11:07:20.010 に答える