Transition Animation--catransitionCatransition is a subclass of caanimation that is used to animate transitions and animate layers to move out of the screen and into the screen. iOS has less transition animations than Mac OS xUinavigationcontroller is the animation effect of pushing the controller's view into the screen via CatransitionAnimation Properties:–type: Animation transition Type–subtype: Animation transition Direction–startprogress: Start of Animation (percentage in overall animation)–endprogress: End of Animation (percentage in overall animation) Transition Effect:Transition Direction:
Ca_extern NSString * Const kcatransitionfromright//animation from right to left
Ca_extern NSString * Const KCATRANSITIONFROMLEFT//animation from left to right
Ca_extern NSString * Const KCATRANSITIONFROMTOP//animation from bottom to top
Ca_extern NSString * Const KCATRANSITIONFROMBOTTOM//animation from top down
The concrete examples are as follows:
Implement features: Import 5 picture footage into the project, create an Image view control, and then rotate the picture in the image view by swiping left or right to achieve a transition animation.
The code is as follows:
Import picture Footage
declaring properties
#import " ViewController.h " @interface *imageview; // Image View @property (assign,nonatomic) Nsinteger index; // index of the current picture @end
Initialize, create an Image view control and set up a picture while creating sweep gestures, adding sweep events
- (void) viewdidload {[Super viewdidload]; //set the current picture to the first oneSelf.index =1; //initializing an image viewSelf.imageview =[[Uiimageview alloc]initwithframe:self.view.frame]; Self.imageView.contentMode=Uiviewcontentmodescaleaspectfit; [Self.imageview setimage:[uiimage imagenamed:[nsstring stringWithFormat:@"s%ld.jpg", Self.index]]; //allow user interaction with image viewsself.imageView.userInteractionEnabled =YES; [Self.view AddSubview:self.imageView]; //Create sweep handsUiswipegesturerecognizer *leftswipe =[[Uiswipegesturerecognizer alloc]initwithtarget:self Action: @selector (swipe:)]; //set sweep direction to swipe leftLeftswipe.direction =Uiswipegesturerecognizerdirectionleft; //Add sweep hands[Self.imageview Addgesturerecognizer:leftswipe]; //Create sweep handsUiswipegesturerecognizer *rightswipe =[[Uiswipegesturerecognizer alloc]initwithtarget:self Action: @selector (swipe:)]; //set sweep direction to right sweepRightswipe.direction =Uiswipegesturerecognizerdirectionright; //Add sweep hands[Self.imageview addgesturerecognizer:rightswipe];}
Handle Sweep action events, create transitions animations and perform animations
#pragma mark sweep hands- on-(void) Swipe: (Uiswipegesturerecognizer *) sender{//Change the index of the picture according to the direction of the gesture, altogether 5 pictures if(sender.direction = = Uiswipegesturerecognizerdirectionleft)//Swipe left { if(Self.index >1) {Self.index--; } Else{Self.index=5; } } Else //Swipe Right { if(Self.index <5) {Self.index++; } Else{Self.index=1; } } //Add Transition AnimationsCatransition *transition =[[Catransition alloc]init]; //transition Type class cube rollover effectTransition.type =@"Cube"; //transition direction is flipped from bottom to topTransition.subtype =Kcatransitionfrombottom; //Animation DurationTransition.duration =1.0f; //Add Transition Animations[Self.imageView.layer addanimation:transition Forkey:@"transition"]; //set up a picture of the image view after each transition animation[Self.imageview setimage:[uiimage imagenamed:[nsstring stringWithFormat:@"s%ld.jpg", Self.index]];}
The demo results are as follows:
Start: Left sweep or right sweep: animated three-dimensional flip from top to bottom
IOS: Transition animation catransition of the core animation