When you need to change the stage background, the stage curtain will slowly close, then open slowly, the content on the stage has changed.
The meaning of transition animation is similar to the stage curtain, when the content on the layer changes, we want to use an animated effect to switch, Coreanimation provides catransition to achieve the transition effect.
- (void) viewdidload{[Super Viewdidload]; Uiimageview*imageview = [[Uiimageview alloc] Initwithframe:cgrectmake ( -, -, -, -)]; Imageview.image= [UIImage imagenamed:@"5.png"]; [Self.view Addsubview:imageview]; Uiimageview*imageview2 = [[Uiimageview alloc] Initwithframe:cgrectmake ( -, -, -, -)]; Imageview2.image= [UIImage imagenamed:@"4.png"]; [Self.view addsubview:imageview2];}- (void) touchesended: (Nsset *) touches withevent: (Uievent *)Event{catransition*transition =[catransition animation]; Transition.type=Kcatransitionmovein; Transition.subtype=Kcatransitionfromleft;
Transition.duration = 1;
[Self.view.layer addanimation:transition forkey:nil]; [Self.view Exchangesubviewatindex: 2 withsubviewatindex:3];}
Catransition two key parameters need to be set: Type and subtype, which control the types of transition animations, which control the direction of transition animation
Type supports the following values
Kcatransitionfade Fade Effect
Kcatransitionmovein Move-in effect
Kcatransitionpush push-in effect
Kcatransitionreveal Uncover Effects
In addition to the above four values, type also supports the following private animations
Cube Cube rotation
Suckeffect Inhalation effect
Oglflip Flip
Rippleeffect Water Wave Animation
Pagecurl Page Uncovered
Pageuncurl PAGE Down
Camerairishollowopen Lens Open
Camerairishollowclose Lens off
The subtype provides four animation orientations and supports the following values
Kcatransitionfromright
Kcatransitionfromleft
Kcatransitionfromtop
Kcatransitionfrombottom
In addition, transition animations can be achieved via UIView's beginanimation:context: and Commitanimation
- (void) viewdidload{[Super Viewdidload]; Uiimageview*imageview = [[Uiimageview alloc] Initwithframe:cgrectmake ( -, -, -, -)]; Imageview.image= [UIImage imagenamed:@"5.png"]; [Self.view Addsubview:imageview]; Uiimageview*imageview2 = [[Uiimageview alloc] Initwithframe:cgrectmake ( -, -, -, -)]; Imageview2.image= [UIImage imagenamed:@"4.png"]; [Self.view addsubview:imageview2];}- (void) touchesended: (Nsset *) touches withevent: (Uievent *)Event{[UIView beginanimations:nil context:nil]; [UIView setanimationduration:0.5]; [UIView Setanimationtransition:uiviewanimationtransitioncurldown ForView:self.view Cache:yes]; [UIView Setanimationcurve:uiviewanimationcurveeasein]; [Self.view Exchangesubviewatindex:2Withsubviewatindex:3]; [UIView commitanimations];}
Setaniamtiontransition supports the following properties
Uiviewanimationtransitionnone No animations
Uiviewanimationtransitionflipfromleft slide in from the left
Uiviewanimationtransitionflipfromright slide in from the right
Uiviewanimationtransitioncurlup opened the pages
Uiviewanimationtransitioncurldown down the pages.
Setaniamtioncurve supports the following properties
Uiviewanimationcurveeaseinout //Slow at beginning and end
Uiviewanimationcurveeasein //slow at beginning
Uiviewanimationcurveeaseout //Slow at end
Uiviewanimationcurvelinear
iOS animation (5) Transition animation