Use animation to control animations under UIView

Source: Internet
Author: User

Reprinted from: http://blog.csdn.net/xunyn/article/details/8128031

Animation is one of the most important features of the iOS interface, where Caanimation is the abstract parent of all animated objects and, as a newcomer, uses more of the animation method (class method) under UIView. There are several ways to use the animation under UIView.

Method One: Set Beginanimations

Where Memberview is a view of the child view that needs to be added, Mivc.view is a sub-view, when used, you need to replace these two places

[CPP]View Plaincopyprint?
    1. [UIView beginanimations:@"View Flip" context:nil];
    2. [UIView Setanimationduration:1];
    3. [UIView setanimationtransition:uiviewanimationtransitionflipfromright Forview:memberview Cache:YES];
    4. [Memberview AddSubview:mivc.view];
    5. [UIView commitanimations];


It should be noted that [UIView commitanimations] must be used and the animation will take effect

by [UIView Setanimationduration:1]; 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 a UIView class method, but using the Block object, the Block object is a set of instructions that can be passed (like a variable) and can be imagined as a C-language function pointer.

Method Two:

Where in the current view, delete [Blueviewcontroller view], add [Yellowviewcontroller view], when used, these two places to replace

[CPP]View Plaincopyprint?
    1. [UIVIEW TRANSITIONWITHVIEW:SELF.VIEW  
    2.                       duration:0.2  
    3.                        options: uiviewanimationoptiontransitionflipfromleft  
    4.                     animations:^{ [[ Blueviewcontroller view] removefromsuperview]; [[self view] insertsubview: yellowviewcontroller.view atindex:0]; }  
    5.                     completion:NULL];   

Where animations: After the block is a change to a particular view, it cannot be null,completion: after the block for the animation after the execution of the code block, you can be null.

According to the manual, during the entire animation process, user interaction is temporarily invalid for this view (and before IOS5.0, the user interaction is not valid for the entire application during the animation process), and if you want the user to interact with the view, you can change UIViewAnimationOptionAllowUserInteraction the value.

Use animation to control animations under UIView

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.