这可能听起来很有趣,但我花了数小时试图重新使用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)]; } }
理想情况下,我可以利用一个数值来告诉我,如果旋转是正还是负。