(1) Add the quartzcore. framework component to the project.
(2) Add
# Import <quartzcore/quartzcore. h> so that all required files can be directly used
(3)
-(Ibaction) clicktosecond :( ID) sender {
// Load the view to be switched
Uiviewcontrollersecond * secondview = [[uiviewcontrollersecond alloc]
Initwithnibname: @ "uiviewcontrollersecond" Bundle: Nil];
// PASS Parameters
Secondview. View. Frame = self. View. frame;
// Set it to the same-level view of the current view
[Self. viewaddsubview: secondview. View];
// Define the animation type
Catransition * animation = [catransition animation];
Animation. Delegate = self;
Animation. Duration = 1.25f;
Animation. timingfunction = [camediatimingfunction functionwithname: kcamediatimingfunctioneaseineaseout];
Animation. fillmode = kcafillmodeforwards;
Animation. type = kcatransitionfade;
Animation. Subtype = kcatransitionfromright;
[Self. View. Layer
Addanimation: animationforkey: @ "Animation"];
}
-(Ibaction) clickreturnhome: (ID) sender {
Catransition * animation = [catransition
Animation];
Animation. Delegate = self;
Animation. Duration = 0.50f;
Animation. timingfunction = [camediatimingfunction functionwithname: kcamediatimingfunctioneaseineaseout];
Animation. fillmode = kcafillmodeboth;
Animation. type = kcatransitionfade;
Animation. Subtype = kcatransitionfromright;
[Self. View. superview. Layer
Addanimation: animationforkey: @ "Animation"];
[Self. viewremovefromsuperview];
}
Note: The relationship between the two views is parent-child view.
For details about how to switch the view, see viewtransitions.