這可能聽起來很有趣,但我花了數小時試圖重新使用UIView和一些三角現實旋轉的旋鈕。我達到了目標,但現在我無法弄清楚如何知道旋鈕是左旋還是右旋。數學是最相關的部分是在這裏:得到UIView的旋轉方向touchesMoved
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint pt = [touch locationInView:self]; float dx = pt.x - iv.center.x; float dy = pt.y - iv.center.y; float ang = atan2(dy,dx); //do the rotation if (deltaAngle == 0.0) { deltaAngle = ang; initialTransform = iv.transform; }else { float angleDif = deltaAngle - ang; CGAffineTransform newTrans = CGAffineTransformRotate(initialTransform, -angleDif); iv.transform = newTrans; currentValue = [self goodDegrees:radiansToDegrees(angleDif)]; } }
理想情況下,我可以利用一個數值來告訴我,如果旋轉是正還是負。