Zoom in View-> rotate-> restore animation, view animation
Take UIButton as an example to create a class that inherits from UIButton.
/* Create a storyboard for the page */
. H file
@ Interface PTSRecommendButton: UIButton
-(Void) viewTransform;
@ End
. M file
@ Implementation PTSRecommendButton
-(Void) viewTransform {
//
[Self. layer setAnchorPoint: CGPointMake (1, 0.5)];
CGRect btnFrame = self. frame;
// Set the AnchorPoint to 0.5 by default.
BtnFrame. origin. x + = btnFrame. size. width/2;
Self. frame = btnFrame;
// Zoom in
[UIView transitionWithView: self duration: 0.5 options: UIViewAnimationOptionAllowUserInteraction animations: ^ {
// Because the button is clicked during the animation line, if there is no page Jump operation. You need to set that the dog cannot be clicked, or it will overwrite the animation method.
// Self. userInteractionEnabled = NO;
Self. transform = CGAffineTransformMakeScale (1.2, 1.2 );
} Completion: ^ (BOOL finished ){
// Restore the central point
[Self. layer setAnchorPoint: CGPointMake (0.5, 0.5)];
CGRect btnFrame = self. frame;
BtnFrame. origin. x-= btnFrame. size. width/2;
Self. frame = btnFrame;
// Rotate
[UIView transitionWithView: self duration: 0.25 options: UIViewAnimationOptionAllowUserInteraction animations: ^ {
//
Self. transform = CGAffineTransformRotate (self. transform, M_PI * 0.05 );
} Completion: ^ (BOOL finished ){
// Reverse Rotation
[UIView transitionWithView: self duration: 0.5 options: UIViewAnimationOptionAllowUserInteraction animations: ^ {
Self. transform = CGAffineTransformRotate (self. transform,-M_PI * 0.1 );
} Completion: ^ (BOOL finished ){
// Return to the initial rotation state
[UIView transitionWithView: self duration: 0.25 options: UIViewAnimationOptionAllowUserInteraction animations: ^ {
Self. transform = CGAffineTransformRotate (self. transform, M_PI * 0.05 );
} Completion: ^ (BOOL finished ){
// Restore the central point
[Self. layer setAnchorPoint: CGPointMake (1, 0.5)];
CGRect btnFrame = self. frame;
BtnFrame. origin. x + = btnFrame. size. width/2;
Self. frame = btnFrame;
// Restore the initial state
[UIView transitionWithView: self duration: 0.5 options: UIViewAnimationOptionAllowUserInteraction animations: ^ {
Self. transform = CGAffineTransformIdentity;
} Completion: ^ (BOOL finished ){
[Self. layer setAnchorPoint: CGPointMake (. 5, 0.5)];
CGRect btnFrame = self. frame;
// Set the AnchorPoint to 0.5 by default.
BtnFrame. origin. x-= btnFrame. size. width/2;
Self. frame = btnFrame;
// Self. userInteractionEnabled = YES;
}];
}];
}];
}];
}];
}
@ End