1

Hello All I want to rotate UIView on single finger touch and it still rotate untill finger moves on screen of iPhone and it stops rotation when I stop the finger moving or remove it from screen.

Thanks in Advance.

3 Answers 3

8

Try similar code

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.2];
    CGAffineTransform rr=CGAffineTransformMakeRotation(5);
    yourView.transform=CGAffineTransformConcat(yourView.transform, rr);
    [UIView commitAnimations];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    [self touchesBegan:touches withEvent:event];
}
0
6

Pradeepa's code is nice, however, that animation system is getting deprecated (if not already). Try something like this instead:

CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
double startRotationValue = [[[yourView.layer presentationLayer] valueForKeyPath:@"transform.rotation.z"] doubleValue];
rotation.fromValue = [NSNumber numberWithDouble:startRotationValue];
rotation.toValue = [NSNumber numberWithDouble:startRotationValue+5];
rotation.duration = 0.2;
[yourView.layer addAnimation:rotation forKey:@"rotating"];

I took Pradeepa's numbers to make them comparable, but i believe Apple prefers you using this or block-based animation instead of the old system.

0
1

rotating a view on touch may help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.