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.
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.
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]; }
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.
rotating a view on touch may help you