Zoom-& gt; rotate-& gt; restore animation, View animation

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.