视图切换,没有NavigationController的情况下,一般会使用presentViewController来切换视图并携带切换时的动画,
其中切换方法如下:
– presentViewController:animated:completion: 弹出,出现一个新视图 可以带动画效果,完成后可以做相应的执行函数经常为nil
– dismissViewControllerAnimated:completion:退出一个新视图 可以带动画效果,完成后可以做相应的执行函数经常为nil
切换动画在压入一个新视图和弹出顶层视图均可以使用,下面只以压入视图为例。
presentModalViewController:animated:completion:使用系统自带四种动画
简单的实现方式:
[page2Controller setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:myNextViewController animated:YES completion:nil];
系统支持的四种动画:
typedefenum{
UIModalTransitionStyleCoverVertical=0,//默认方式,竖向上推
UIModalTransitionStyleFlipHorizontal,//水平反转
UIModalTransitionStyleCrossDissolve,//隐出隐现
UIModalTransitionStylePartialCurl,//部分翻页效果
} UIModalTransitionStyle;
presentModalViewController:animated:completion:
不用自带的四种动画效果
实现全翻页效果:
CATransition *animation = [CATransition animation];
animation.duration =1.0;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.type =@"pageCurl";
//animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromLeft;
[self.view.window.layer addAnimation:animation forKey:nil];
[self presentModalViewController:myNextViewController animated:NO completion:nil];
常見的轉換類型(type):
kCATransitionFade//淡出
kCATransitionMoveIn//覆盖原图
kCATransitionPush//推出
kCATransitionReveal//底部显出来
SubType:
kCATransitionFromRight
kCATransitionFromLeft// 默认值
kCATransitionFromTop
kCATransitionFromBottom
设置其他动画类型的方法(type):
pageCurl 向上翻一页
pageUnCurl 向下翻一页
rippleEffect 滴水效果
suckEffect 收缩效果,如一块布被抽走
cube 立方体效果
oglFlip 上下翻转效果
#define 自定义present页面
+ (void)presentViewStyle:(NSString *)style view:(UIView *)view {
CATransition *animation = [CATransition animation];
animation.duration = 0.6;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.type = style;
animation.subtype = kCATransitionFade;
[view.window.layer addAnimation:animation forKey:nil];
}
网友评论