一、 present简单的实现方式:
ViewController2 *vc = [[ViewController2 alloc]init];
[vc setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentViewController:vc animated:YES completion:nil];
1、其中Xcode自带四种动画::
typedef enum {UIModalTransitionStyleCoverVertical=0, //默认方式,竖向上推
UIModalTransitionStyleFlipHorizontal, //水平反转
UIModalTransitionStyleCrossDissolve,//隐出隐现
UIModalTransitionStylePartialCurl,//部分翻页效果}
UIModalTransitionStyle;
presentModalViewController:animated:completion: 不用自带的四种动画效果
2、实现全翻页效果:
ViewController2 *vc = [[ViewController2 alloc]init];
[vc setModalTransitionStyle:UIModalTransitionStylePartialCurl];
CATransition *animation = [CATransition animation];
animation.duration = 1.0;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.type = @"pageCurl";//animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromLeft;[vc setValue:@"value" forKey:@"value"];
[self.view.window.layer addAnimation:animation forKey:nil];
[self presentViewController:vc animated:YES completion:nil];
3、常见的转换类型(type):
kCATransitionFade //淡出kCATransitionMoveIn //覆盖原图kCATransitionPush //推出kCATransitionReveal //底部显出来SubType:kCATransitionFromRightkCATransitionFromLeft // 默认值kCATransitionFromTopkCATransitionFromBottom
4、设置其他动画类型的方法(type):
pageCurl 向上翻一页pageUnCurl 向下翻一页rippleEffect 滴水效果suckEffect 收缩效果,如一块布被抽走cube 立方体效果oglFlip 上下翻转效果
二、navigation的使用
For Push:
MainView *nextView=[[MainView alloc] init];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController:nextView animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[nextView release];
For Pop:
方法一:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];
方法二:
//可实现左右滑动动画,可设置滑动方向。
CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
//transition.subtype = kCATransitionFromTop; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[[self navigationController] popViewControllerAnimated:NO];