Recently in a small project encountered an animation switch effect, a moment be to, and then went to see the apple provided by the animation class, found a few animation execution methods, these default animation method enough to meet the general needs of the animation effect, followed by the code First we create the corresponding button button in the controller cgfloat mainheight = [UIScreen mainscreen].bounds.size.height; NsarrayTitlearr = @[@ "Add", @ "page", @ "move in", @ "uncover", @ "cube", @ "shrink" @ "Flip", @ "water wave"]; for (int i = 0; i < 8; i + +) {UIButtonbutton = [UIButton Buttonwithtype:uibuttontypesystem]; Button.tag = + i; [Button settitle:titlearr[i] forstate:uicontrolstatenormal]; Four buttons per line nsinteger row = I/4; Nsinteger col = i% 4; [Button addtarget:self action: @selector (changepageanimation:) forcontrolevents:uicontroleventtouchupinside]; Button.frame = CGRectMake (5 + col80,mainheight-(2-row)45-20, 70, 40); [Self.view Addsubview:button]; After creating the button we can add some view controls, here I added two UIView as a demo: UIViewPurpleview = [[UIView alloc] initWithFrame:self.view.bounds]; purpleview.backgroundcolor = [Uicolor Purplecolor]; [Self.view Addsubview:purpleview]; UIViewBlackview = [[UIView alloc] initWithFrame:self.view.bounds]; Blackview.backgroundcolor = [Uicolor blackcolor]; [Self.view Addsubview:blackview]; Note that the UIView hierarchy is followed by the click Method of the button, where I use the tag value to fetch the current button
-
(void) Changepageanimation: (UIButton *) Sender {switch (sender.tag) {case 100: {//Start animation [UIView beginanimations:@] Anima tion "Context:nil"; [UIView setanimationduration:1.0f]; Controls the type of transition animation within UIView [UIView Setanimationtransition:uiviewanimationtransitioncurldown ForView:self.view Cache:yes]; Set the animation's change curve [UIView setanimationcurve:uiviewanimationcurveeaseinout]; [Self.view Exchangesubviewatindex:3 Withsubviewatindex:2]; Commit animation [UIView commitanimations]; } break; Case 101: {//Start animation [UIView beginanimations:@ "animation" context:nil]; [UIView setanimationduration:1.0f]; Controls the type of transition animation within UIView [UIView Setanimationtransition:uiviewanimationtransitioncurlup ForView:self.view Cache:yes]; Set the animation's change curve [UIView setanimationcurve:uiviewanimationcurveeaseout]; The Swap view controller displays 2 child control locations in UIView [Self.view exchangesubviewatindex:3 withsubviewatindex:2];
[UIView commitanimations];}BreakCase102:{Catransition *transition = [Catransition Animation]; Transition.duration =2.0f;Use Kcatransitionmovein animation transition.type = Kcatransitionmovein;Specifies the direction of animation, from left to right transition.subtype = Kcatransitionfromleft; [Self.view.layerAddanimation:transitionforkey:@"Animation"]; [Self.viewExchangesubviewatindex:2Withsubviewatindex:3];}BreakCase103:{Catransition *transition = [Catransition Animation]; Transition.duration =2.0f;Use kcatransitionreveal animation transition.type = Kcatransitionreveal;Specifies the direction of animation, from top to bottom transition.subtype = kcatransitionfromleft; [Self.view.layerAddanimation:transitionforkey:@"Animation"];The interchange View controller displays theIn the middle of UIView2 Child control Locations [Self.viewExchangesubviewatindex:2Withsubviewatindex:3];}BreakCase104:{Catransition *transition = [Catransition Animation]; Transition.duration =2.0f;Use"Cube" Animation Transition.type = @"Cube";Specifies the direction of the animation, from left to right transition.subtype = Kcatransitionfromleft; [Self.view.layerAddanimation:transitionforkey:@"Animation"];The interchange View controller displays theIn the middle of UIView2 Child control Locations [Self.viewExchangesubviewatindex:2Withsubviewatindex:3];}BreakCase105:{Catransition *transition = [Catransition Animation]; Transition.duration =2.0f;Use"Suck" animation, the animation is independent of the direction of the animation Transition.type = @"Suckeffect"; [Self.view.layerAddanimation:transitionforkey:@"Animation"];The interchange View controller displays theIn the middle of UIView2 Child control Locations [Self.viewExchangesubviewatindex:2Withsubviewatindex:3];}BreakCase106:{Catransition *transition = [Catransition Animation]; Transition.duration =0.5f;Use"Oglflip" Animation Transition.type = @"Oglflip";Specifies that the animation direction is upside down transition.subtype = kcatransitionfromtop; [Self.view.layerAddanimation:transitionforkey:@"Animation"];The interchange View controller displays theIn the middle of UIView2 Child control Locations [Self.viewExchangesubviewatindex:1Withsubviewatindex:3];}BreakCase107:{Catransition *transition = [catransition animation]; Transition.duration = 2.0f; //use @ "Rippleeffect" animation, the animation is independent of direction Transition.type = @ "Rippleeffect"; [self.view.layer addanimation:transition forkey:@ "animation"]; //swap View Controller displays uiview in 2 child control locations [ Span class= "Hljs-keyword" >self.view exchangesubviewatindex:2 withsubviewatindex:3];} break; default: break;
}} The final implementation effect is this
View Toggle animation effect in IOS Controller