My iOS Learning Path (iv): animation settings

Source: Internet
Author: User

In the development process of iOS, it is often necessary to change the view control, such as size, color, rotation, etc., which is not friendly if the result of the change is presented directly, so we usually use animation, so that the user can see the change process.

There are usually two ways to use animations, one between blocks of code and the other with block blocks.

Next, we'll start with code blocks.

 

1   //using a block of code requires only the control that will be changed, and the action in the change is placed in the code block2           //Animation Head3 [UIView Beginanimations:nil context:nil];4          //Animation finish Time5[UIView setanimationduration:1];6          //Change frame here for label7UILabel *label.frame = CGRectMake ( the,480, -, -);8           //animation trailer, Commit, execute animation9[UIView commitanimations];

There are two ways to animate using block, the first of which is by calling the [UIView animatewithduration:nstimeinterval animations:^ (void) Animations] Method

  

1 // put the code that needs to be animated into the block 2 // where the first parameter is the animation time 3 [UIView animatewithduration:1 animations:^{4//             Label.frame = CGRectMake (label.frame.origin.x, LABEL.FRAME.ORIGIN.Y, Width, HEIGHT); 5 //         }];

The second method is to call the

[UIView animatewithduration: (nstimeinterval) animations:^ (void) animations completion:^ (BOOL finished) completion] method , this method is a reinforced version of the previous method, which executes the last block after the animation operation

1UIView *view =[[UIView alloc] init];2View.frame = CGRectMake (0,0, -, -);3View.backgroundcolor =[Uicolor Greencolor];4     //animating with Block5 //[UIView animatewithduration:5 animations:^{6 //view.frame = CGRectMake (n/ A, +/-);7 //View.backgroundcolor = [Uicolor redcolor];8 //    }];9     //after an animation block executes, continue with the last blockTen[UIView animatewithduration:5animations:^{ OneView.frame = CGRectMake ( -, the, +, +); AView.backgroundcolor =[Uicolor Redcolor]; -} completion:^(BOOL finished) { -[UIView animatewithduration:5animations:^{ theView.frame = CGRectMake (0,0, -, -); -View.backgroundcolor =[Uicolor Yellowcolor]; -View.alpha =0.1; -         }]; +}];

My iOS Learning Path (iv): animation settings

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.