Used to animate transitions, which gives the layer an animated effect of moving out of the screen and moving into the screen. iOS has less transition animations than Mac OS X
Uinavigationcontroller is the animation effect of pushing the controller's view into the screen via catransition
Attribute parsing:
Type: Animation transition types
Subtype: Animation transition Direction
Startprogress: Start of Animation (percentage in overall animation)
Endprogress: End of Animation (percentage in overall animation)
Code One:
#import "ViewController.h" @interface Viewcontroller () @property (nonatomic,strong) Uiimageview *imgview;@ End@implementation viewcontroller-(void) viewdidload {[Super viewdidload]; Self.imgview=[[uiimageview Alloc]initwithframe:cgrectmake (100, 200, 200, 200)]; [Self.view AddSubview:self.imgView]; UIButton *btn1=[uibutton Buttonwithtype:uibuttontypecustom]; [Btn1 settitle:@ "on a" forstate:uicontrolstatenormal]; [Btn1 addtarget:self Action: @selector (Btnclick:) forcontrolevents:uicontroleventtouchupinside]; btn1.tag=1; Btn1.backgroundcolor=[uicolor Redcolor]; Btn1.frame=cgrectmake (50, 100, 80,40); [Self.view ADDSUBVIEW:BTN1]; UIButton *btn2=[uibutton Buttonwithtype:uibuttontypecustom]; [Btn2 settitle:@ "Next" forstate:uicontrolstatenormal]; btn2.tag=2; [Btn2 addtarget:self Action: @selector (Btnclick:) forcontrolevents:uicontroleventtouchupinside]; Btn2.frame=cgrectmake (150, 100, 80,40); Btn2.backgroundcolor=[uicolor Redcolor]; [Self. View ADDSUBVIEW:BTN2]; }-(void) Btnclick: (ID) sender{UIButton *btn= (UIButton *) sender; if (btn.tag==1) {self.imgview.image=[uiimage imagenamed:@ "1.jpg"]; Catransition *transition=[catransition Animation]; Animation effect [email protected] "push"; Animation direction transition.subtype=kcatransitionfromright; transition.duration=2.0; [Self.imgView.layer addanimation:transition Forkey:nil]; } else {self.imgview.image=[uiimage imagenamed:@ "2.jpg"]; Catransition *transition=[catransition Animation]; Transition.type=kcatransitionmovein; Transition.subtype=kcatransitionfrombottom; transition.duration=2.0; [Self.imgView.layer addanimation:transition Forkey:nil]; }}-(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
Code two:
Core Animation Catransition (transition animation)