1 Preface
Today, we will learn how to create a rotating affine transform and use the UIView animation method to perform the rotating action.
2. code example
ZYViewController. m
[Plain]
-(Void) viewDidLoad
{
[Super viewDidLoad];
UIImage * xcodeImage = [UIImage imageNamed: @ "Xcode.png"];
Self. xcodeImageView = [[UIImageView alloc] initWithImage: xcodeImage];
// Set the Frame of the image
[Self. xcodeImageView setFrame: CGRectMake (0.0f, 0.0f, 100366f, 100366f)];
Self. view. backgroundColor = [UIColor whiteColor];
[Self. view addSubview: self. xcodeImageView];
}
-(Void) viewDidAppear :( BOOL) paramAnimated {[super viewDidAppear: paramAnimated];
Self. xcodeImageView. center = self. view. center;
/* Begin the animation */
[UIView beginAnimations: @ "clockwiseAnimation" context: NULL];
/* Make the animation 5 seconds long */
[UIView setAnimationDuration: 5.0f];
[UIView setAnimationDelegate: self];
// Call the clockwiseRotationStopped method when the animation is stopped.
[UIView setAnimationDidStopSelector: @ selector (clockwiseRotationStopped: finished: context :)];
// Rotate 90 degrees clockwise
Self. xcodeImageView. transform = CGAffineTransformMakeRotation (90.0f * M_PI)/180.0f );
/* Commit the animation */
[UIView commitAnimations];
}
-(Void) clockwiseRotationStopped :( NSString *) paramAnimationID finished :( NSNumber *) paramFinished
Context :( void *) paramContext {
[UIView beginAnimations: @ "counterclockwiseAnimation" context: NULL];
/* 5 seconds long */
[UIView setAnimationDuration: 5.0f];
/* Return to the original rotation */
Self. xcodeImageView. transform = CGAffineTransformIdentity;
[UIView commitAnimations];
}