views:

74

answers:

1

I have a circular image which i am trying to rotate so that the yellow and black striped circle stays under the users finger and rotates in both directions. I have this so far:

- (void)handleJogShuttle:(UIPanGestureRecognizer *)recognizer {

    UIView *shuttle = [recognizer view];

    if ([recognizer state] == UIGestureRecognizerStateBegan || [recognizer state] == UIGestureRecognizerStateChanged) {

        [recognizer view].transform = CGAffineTransformRotate([[recognizer view] transform],M_PI / 20.0f);
        [recognizer setTranslation:CGPointZero inView:[shuttle superview]];

    }   

}

Also, currently, the slightest movement can cause the view to rotate in a full circle, which is obviously not desired.

Thanks.

A: 

I suspect this method gets called A LOT. Try using NSLog and check how many time it does. Anyway, you are not calculating the angle properly, you could try using - (CGPoint)translationInView:(UIView *)view from the recognizer to calculate the correct angle to rotate.

Paulo Casaretto
How would i use translationInView, as it returns a CGPoint, not an angle? thanks
joec
Find out the center of your circle and calculate the angle from the previous point to the current using the inverse sine our inverse cosine. Its not too complicated, but you would have to compensate for the radial translation. It's hard for me to explain it here.
Paulo Casaretto