In the iOS development generally used in the following types of basic animation, all the animation parameters configuration is roughly the same, but sometimes in the development process rarely such configuration is generally easier to use code blocks, and the code is relatively simple the following is a configuration of common base animation types
#pragma mark-Action methods-(void) transitionanimation//transition Animation {//Set animation name, convenient proxy method to determine which animation [UIView beginanimations:@ "T Ransitionanimation "Context:null"; Set animation duration [UIView setanimationduration:3.0]; Set the change pattern of the animation-there are the following 4 enumeration values//Uiviewanimationcurveeaseinout, start and end deceleration//slow at beginning and end//Uiviewanim Ationcurveeasein,//Slow at beginning//uiviewanimationcurveeaseout,//slow at end//Uiviewan IMATIONCURVELINEAR constant Speed [UIView setanimationcurve:uiviewanimationcurveeaseinout]; The direction of the transition animation to view is set in the following enumeration direction//typedef ns_enum (Nsinteger, uiviewanimationtransition) {//Uiviewanimationtransitionno ne,//uiviewanimationtransitionflipfromleft,//uiviewanimationtransitionflipfromright,//UIViewAnimat iontransitioncurlup,//uiviewanimationtransitioncurldown,//}; [UIView setanimationtransition:uiviewanimationtransitionflipfromright Forview:_view Cache:no]; Set the initial state of the view and configure the other (this is justLet the view become the previous parameter, if you do not need to remove this code) [_view settransform:cgaffinetransformidentity]; [_view Setbackgroundcolor:[uicolor Blackcolor]; [_view setalpha:1]; [_view Setcenter:cgpointmake (50, 50)]; Set agent [UIView setanimationdelegate:self]; End of animation execution Agent method (in this case, the proxy method can also go other animation methods can be formed animation group) [UIView setanimationdidstopselector: @selector (animationdidstop: Finished:context:)]; End of animation [UIView commitanimations];} -(void) changealphaanimation//Change transparency Animation {[UIView beginanimations:@ "Changealphaanimation" context:null]; [UIView setanimationduration:2.0]; [UIView Setanimationcurve:uiviewanimationcurveeaseinout]; [_view setalpha:0.2]; [UIView setanimationdelegate:self]; [UIView setanimationdidstopselector: @selector (animationDidStop:finished:context:)]; [UIView commitanimations];} -(void) changecoloranimation//Change color animation {[UIView beginanimations:@ "Changecoloranimation" context:null]; [UIView setanimationduration:2.0]; [UIView setanimationcurve:uiviewanimationcurvEeaseinout]; [_view Setbackgroundcolor:[uicolor Redcolor]; [UIView setanimationdelegate:self]; [UIView setanimationdidstopselector: @selector (animationDidStop:finished:context:)]; [UIView commitanimations];} -(void) rotationanimation//Rotate animation {[UIView beginanimations:@ "Rotationanimation" context:null]; [UIView setanimationduration:2.0]; [UIView Setanimationcurve:uiviewanimationcurveeaseinout]; [_view settransform:cgaffinetransformrotate (_view.transform, M_pi_4)]; [UIView setanimationdelegate:self]; [UIView setanimationdidstopselector: @selector (changecoloranimation)]; [UIView commitanimations];} -(void) scareanimation//Zoom out animation {[UIView beginanimations:@ "Scareanimation" context:null]; [UIView setanimationduration:2.0]; [UIView Setanimationcurve:uiviewanimationcurveeaseinout]; [UIView setanimationdelegate:self]; [_view Settransform:cgaffinetransformscale (_view.transform, 2, 2)]; [UIView setanimationdidstopselector: @selector (rotationanimation)]; [UIView commitanimations];} -(void) positionanimation//Displacement animation {[UIView beginanimations:@ "Positionanition" context:null]; [UIView setanimationduration:2.0]; [UIView Setanimationcurve:uiviewanimationcurveeaseinout]; [UIView setanimationdelegate:self]; _view.center = Cgpointmake (Cgrectgetmidx (self.view.bounds), Cgrectgetmidy (self.view.bounds)); [UIView setanimationdidstopselector: @selector (scareanimation)]; [UIView commitanimations];} Proxy methods, detecting animations and doing other things there are two other methods-(void) Animationdidstop: (NSString *) Animationid finished: (NSNumber *) finished context :(void *) context{//determines which animation then performs the appropriate action if ([Animationid isequaltostring:@ "Changecoloranimation"]) {[Self cha Ngealphaanimation]; } if ([Animationid isequaltostring:@ "Changealphaanimation"]) {[Self transitionanimation]; }}
Let's take a look at the use of code blocks, the code block is very convenient to use and can execute callbacks, in the app click on the menu Dynamic single switch two view or other animation
<pre name= "code" class= "OBJC" >[uiview animatewithduration:0.5 animations:^{ [UIView setanimationdelay:0.8 ];//Configuration Animation delay _currentview.center = Cgpointmake (x, y),//can be configured for multiple view of the animation we want newview.center = Cgpointmake (x, y) ; } completion:^ (BOOL finished) { //Run the code block after execution }];
iOS UIView performing base animation animation using parameter configuration