我正在使用此示例代码RotationPie。它是一个轮子,我想在一个方向上移动它或在我的项目中旋转它。我想提出不同的选项,用户将不得不选择其中一个。我希望车轮只能朝一个方向旋转。我认为我必须在类CDCircleGestureRecognizer中改变这个方法,但我不知道是什么。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([self state] == UIGestureRecognizerStatePossible) {
[self setState:UIGestureRecognizerStateBegan];
} else {
[self setState:UIGestureRecognizerStateChanged];
}
// We can look at any touch object since we know we
// have only 1. If there were more than 1 then
// touchesBegan:withEvent: would have failed the recognizer.
UITouch *touch = [touches anyObject];
// To rotate with one finger, we simulate a second finger.
// The second figure is on the opposite side of the virtual
// circle that represents the rotation gesture.
CDCircle *view = (CDCircle *) [self view];
CGPoint center = CGPointMake(CGRectGetMidX([view bounds]), CGRectGetMidY([view bounds]));
CGPoint currentTouchPoint = [touch locationInView:view];
CGPoint previousTouchPoint = [touch previousLocationInView:view];
previousTouchDate = [NSDate date];
CGFloat angleInRadians = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x) - atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);
CGFloat one = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x);
CGFloat two =atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);
currentTransformAngle = atan2f(view.transform.b, view.transform.a);
[self setRotation:angleInRadians];
答案 0 :(得分:1)
我认为你应该将当前的angleInRadians存储在变量中,并且只有当新角度比当前角度更大(或更小)时才允许旋转。