最も簡単な方法は、回転値をプロパティとして与えるUIRotationGestureRecognizer
を使用することです。
あなたは(未テスト)は、このような何かをしようと、ジェスチャー認識を使用することができない場合は、次の
// Assuming centerPoint is the center point of the object you want to rotate (the rotation axis),
// currentTouchLocation and initialTouchLocation are the coordinates of the points between
// which you want to calculate the angle.
CGPoint centerPoint = ...
CGPoint currentTouchLocation = ...
CGPoint initialTouchLocation = ...
// Convert to polar coordinates with the centerPoint being (0,0)
CGPoint currentTouchLocationNormalized = CGPointMake(currentTouchLocation.x - centerPoint.x, currentTouchLocation.y - centerPoint.y);
CGPoint initialTouchLocationNormalized = CGPointMake(initialTouchLocation.x - centerPoint.x, initialTouchLocation.y - centerPoint.y);
CGFloat angleBetweenInitialTouchAndCenter = atan2(initialTouchLocationNormalized.y, initialTouchLocationNormalized.x);
CGFloat angleBetweenCurrentTouchAndCenter = atan2(currentTouchLocationNormalized.y, currentTouchLocationNormalized.x);
CGFloat rotationAngle = angleBetweenCurrentTouchAndCenter - angleBetweenInitialTouchAndCenter;
は、極座標の詳細とどのようにデカルトと極の間で変換する方法を学ぶためにウィキペディアを参照するか、Google検索を行います座標系。
答えをありがとう。残念ながら、ジェスチャーは私が好むユーザーインタラクション体験を私に提供しません。例えば、ジェスチャーでは、幅を広げてビューの高さを固定することはできません。さらに、ジェスチャを使用すると、1本の指でオーバーレイを移動することができなくなります。 – adranale
それは何百万回も感謝しました! – adranale