2

このサンプル コード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];
4

1 に答える 1

1

現在の angleInRadians を変数に格納し、新しい角度が現在の角度よりも大きい (または小さい) 場合にのみ回転を許可する必要があると思います。

于 2012-11-12T11:43:50.170 に答える