Use parameter configuration to execute the basic Animation in ios UIView, iosuiview

Source: Internet
Author: User

Use parameter configuration to execute the basic Animation in ios UIView, iosuiview

In ios development, basic animations are generally used in the following types. All animation parameter configurations are roughly the same, but sometimes such configurations are rarely used during development. Generally, it is easier to use code blocks, the Code is also relatively simple. The following is a configuration of common basic animation types.

# Pragma mark -- Action methods-(void) transitionAnimation // transition animation {// set the animation name so that the agent can determine which animation is used. [UIView beginAnimations: @ "TransitionAnimation" context: NULL]; // set the animation duration [UIView setAnimationDuration: 3.0]; // set the animation variation rules-with the following enumerated values in 4 // UIViewAnimationCurveEaseInOut, start and end deceleration // slow at beginning and end // slow, // slow at beginning // slow, // slow at end // UIViewAnimationCurveLinear constant speed [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; // set the following enumeration direction for the View transition animation // typedef NS_ENUM (NSInteger, UIViewAnimationTransition) {// UIViewAnimationTransitionNone, // audience, // audience, // UIViewAnimationTransitionCurlUp, // UIViewAnimationTransitionCurlDown, //}; [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView: _ view cache: NO]; // set the initial state of the View and configure others (here, the View is changed to the previous parameter, and you can remove this Code if you do not need it) [_ view setTransform: CGAffineTransformIdentity]; [_ view setBackgroundColor: [UIColor blackColor]; [_ view setAlpha: 1]; [_ view setCenter: CGPointMake (50, 50)]; // sets the proxy [UIView setAnimationDelegate: self]; // execute the proxy method after the animation ends (when the proxy method is used here, other animation methods can be used to form an animation Group) [UIView setAnimationDidStopSelector: @ selector (animationDidStop: finished: context :)]; // animation end [UIView commitAnimations];}-(void) changeAlphaAnimation // change transparency animation {[UIView beginAnimations: @ "ChangeAlphaAnimation" context: NULL]; [UIView setAnimationDuration: 2.0]; [UIView setAnimationCurve: Unknown]; [_ view setAlpha: 0.2]; [UIView setAnimationDelegate: self]; [UIView attributes: @ selector (animationDidStop: finished: context :)]; [UIView commitAnimations];}-(void) changeColorAnimation // color change animation {[UIView beginAnimations: @ "ChangeColorAnimation" context: NULL]; [UIView setAnimationDuration: 2.0]; [UIView setAnimationCurve: finished]; [_ view setBackgroundColor: [UIColor redColor]; [UIView setAnimationDelegate: self]; [UIView progress: @ selector (animationDidStop: finished: context :)]; [UIView commitAnimations];}-(void) rotationAnimation // rotation animation {[UIView beginAnimations: @ "RotationAnimation" context: NULL]; [UIView setAnimationDuration: 2.0]; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; [_ view setTransform: CGAffineTransformRotate (_ view. transform, M_PI_4)]; [UIView setAnimationDelegate: self]; [UIView setAnimationDidStopSelector: @ selector (changeColorAnimation)]; [UIView commitAnimations];}-(void) scareAnimation // zoom in and out the animation {[UIView beginAnimations: @ "ScareAnimation" context: NULL]; [UIView setAnimationDuration: 2.0]; [UIView setAnimationCurve: animation]; [UIView details: self]; [_ view setTransform: CGAffineTransformScale (_ view. transform, 2, 2)]; [UIView progress: @ selector (rotationAnimation)]; [UIView commitAnimations];}-(void) positionAnimation // displacement animation {[UIView beginAnimations: @ "PositionAnition" context: NULL]; [UIView setAnimationDuration: 2.0]; [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; [UIView setAnimationDelegate: self]; _ view. center = CGPointMake (CGRectGetMidX (self. view. bounds), CGRectGetMidY (self. view. bounds); [UIView setAnimationDidStopSelector: @ selector (scareAnimation)]; [UIView commitAnimations];} // proxy method, there are two other methods to detect the animation and perform other operations-(void) animationDidStop :( NSString *) animationId finished :( NSNumber *) finished context :( void *) context {// determine which animation is and then perform the corresponding operation if ([animationId isEqualToString: @ "ChangeColorAnimation"]) {[self changeAlphaAnimation];} if ([animationId isEqualToString: @ "ChangeAlphaAnimation"]) {[self transitionAnimation];}


Next let's take a look at the usage of the code block. It is very convenient to use the code block and can be called back. In the APP click the menu to dynamically switch between two views or other animations.

<Pre name = "code" class = "objc"> [UIView animateWithDuration: 0.5 animations: ^ {[UIView setAnimationDelay: 0.8]; // configure the animation latency _ currentView. center = CGPointMake (X, Y); // you can configure newView for multiple views. center = CGPointMake (X, Y);} completion: ^ (BOOL finished) {// code block after execution}];


 



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.