Use Animation to control Animation in UIView

Source: Internet
Author: User

Animation effect is one of the important features of the IOS interface. CAAnimation is the abstract parent class of all animation objects. For new users, animation methods (class methods) under UIView are mostly used ). You can use the following methods to use an animation under UIView.

Method 1: Set beginAnimations

Here, memberView is the view of the subview to be added, and mivc. view is the subview. You need to replace these two places when using it.

[Cpp]
[UIView beginAnimations: @ "view flip" context: nil];
[UIView setAnimationDuration: 1];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView: memberView cache: YES];
[MemberView addSubview: mivc. view];
[UIView commitAnimations];

Note that [UIView commitAnimations] must be used for the animation to take effect.
Use [UIView setAnimationDuration: 1]; To set the duration.

After IOS4.0, we have a new method, + (void) transitionWithView :( UIView *) view duration :( NSTimeInterval) duration options :( UIViewAnimationOptions) options animations :( void (^) (void) animations completion :( void (^) (BOOL finished) completion is still the class method of UIView, but the Block object is used, and the Block object is a set of commands, it can be passed (like a variable) and imagined as a function pointer in C language.

Method 2:

In the current view, delete [blueViewController view] and add [yellowViewController view]. during use, replace

[Cpp]
[UIView transitionWithView: self. view
Duration: 0.2
Options: UIViewAnimationOptionTransitionFlipFromLeft
Animations: ^ {[[blueViewController view] removeFromSuperview]; [[self view] insertSubview: yellowViewController. view atIndex: 0];}
Completion: NULL];
Animations: The block after the animation is changed to a specific view. The block cannot be NULL, And the completion is the code block to be executed after the animation is executed. The block can be NULL.
According to the manual, user interaction is temporarily ineffective for this view during the entire animation process (whereas before IOS5.0, user interaction is ineffective for the entire application during the animation process ), if you want to interact with a view, you can change the value of UIViewAnimationOptionAllowUserInteraction.

 

 


 

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.