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