IOS: animation, ios Animation

Source: Internet
Author: User

IOS: animation, ios Animation

1. UIView Animation

1-1), original, non-Block.

// The animation name and content [UIView beginAnimations: @ "id100" context: @ "animation1"]; // The duration is 2 seconds. [UIView setAnimationDuration: 2.0]; // The animation starts slowly, no uniform speed // UIViewAnimationCurveEaseInOut, // slow in, slow out // slow, // slow in // slow out, // slow out // UIViewAnimationCurveLinear, // constant speed [UIView setAnimationCurve: UIViewAnimationCurveEaseIn]; // sets the proxy [UIView setAnimationDelegate: self]; // The animation is about to start SEL [UIView setAnimationWillStartSelector: @ selector (animationWillStart: context :)]; // The animation is about to end SEL [UIView setAnimationDidStopSelector: @ selector (animationDidStop: finished: context :)]; // submit the animation [UIView commitAnimations]; // after signing the proxy, in order to implement the SEL method (the method name is random and the number of parameters is also random. When there are less than 2/3 parameters, only the first few parameters are received, more than its parameters, and the following parameters are blank, callback functions that have used C should be familiar with) // Method for starting the animation-(void) animationWillStart :( NSString *) animationID context :( void *) context {NSLog (@ "animation start");} // Method for ending the animation-(void) animationDidStop :( NSString *) animationID finished :( NSNumber *) finished context :( void *) context {// you can determine the ID and perform a continuous animation NSLog (@ "animation ends");} // name yourself-(void) theAnimationStop :( NSString *) animationID thecontext :( void *) theContext context :( void *) context2 {NSLog (@ "% @, % @, % @", animationID, theContext, context2 );}

1-2) Block

// Nested for continuous animation [UIView animateWithDuration: 2.0 animations: ^ {self. cyanVIew. frame = CGRectMake (100,400,100,100);} completion: ^ (BOOL finished) {[UIView animateWithDuration: 2.0 animations: ^ {self. cyanVIew. frame = CGRectMake (100,100,100,100);}];

 

2. Transition)

2-1), original

// Create CATransition * animation = [CATransition animation]; // animation time animation. duration = 1.5; // animation type // kCATransitionFade // fade in // kCATransitionMoveIn // overwrite // kCATransitionPush // push // kCATransitionReveal // set off, relatively overwrite // @ "cube" // cube (AR switching of a certain treasure) // @ "suckEffect" // suck // @ "oglFlip" // flip (a message, friend history, View Details) // @ "rippleEffect" // ripple // @ "pageCurl" // flip over the calendar // @ "pageUnCurl" // calendar cover /// @ "cameraIrisHollowOpen" // camera opens // @ "cameraIrisHollowClose" // The camera closes the animation. type = @ "cube "; // animation direction // kCATransitionFromRight // from the right // kCATransitionFromLeft // from the left // kCATransitionFromTop // from the top /kcatransitionfrombottom // from the following animation. subtype = kCATransitionFromLeft; // animation speed (slow in and out) // kCAMediaTimingFunctionLinear // constant speed // slow in // kCAMediaTimingFunctionEaseOut // slow out // slow in/// kCAMediaTimingFunctionDefault // constant speed, but a little fast animation. timingFunction = [CAMediaTimingFunction functionWithName: role]; // proxy //-(void) animationDidStart :( CAAnimation *) anim; //-(void) animationDidStop :( CAAnimation *) anim finished :( BOOL) flag; animation. delegate = self; // 1. Add an animation to the navigation bar [self. navigationController. view. layer addAnimation: animation forKey: @ "animation"]; [self. navigationController pushViewController: vc animated: NO]; // 2. Add an animation to a normal View [bgView. layer addAnimation: animation forKey: @ "animation"]; // place the Top View to the bottom layer. Generally, transfer between two layers may also be used. exchangeSubviewAtIndex: withSubviewAtIndex: [bgView sendSubviewToBack: [[bgView subviews] lastObject];

2-2) encapsulated, concise, with UIView Animation, View method, non-Layer

// Parameter cache. YES indicates the next transfer, which reduces the burden on the system. The animation is smoother. NO indicates an animation. For example, the animation effect of the edge transition and edge is required. // UIViewAnimationTransitionFlipFromLeft, // bottom turning effect on the left (X letter, friend history, View Details) // UIViewAnimationTransitionFlipFromRight, // bottom turning effect on the right // UIViewAnimationTransitionCurlUp, // flip over the calendar effect // UIViewAnimationTransitionCurlDown, // cover the Calendar effect // 1. navigation bar transition [UIView animateWithDuration: 2.0 animations: ^ {[UIView setAnimationTransition: preview forView: self. navigationController. view cache: YES]; [self. navigationController pushViewController: vc animated: NO];}]; // 2. Place the current View at the bottom layer in normal View transition mode, preferably with the same size, otherwise, the animation effect will be embarrassing [UIView animateWithDuration: 2.0 animations: ^ {// transfer animation [UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView: bgView cache: YES]; // put the top View to the bottom [bgView sendSubviewToBack: [[bgView subviews] lastObject];}];

2-3) modal view transition animation provided by VC

// Set the transition effect of the modal view (for example, letter X, friend's history statement, and click to view details ). Second. modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; // push [self presentViewController: second animated: YES completion: ^ {}];

  

  

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.