ios开发控制器动画

来源:互联网 发布:西安黑马程序员好吗? 编辑:程序博客网 时间:2024/05/18 04:01

一、模态视图动画

1、通过modalTransitionStyle属性来设置弹出模态视图的转场动画,即过渡样式

UIModalTransitionStyleCoverVertical // 底部滑入。UIModalTransitionStyleFlipHorizontal // 水平翻转。UIModalTransitionStyleCrossDissolve // 交叉溶解。UIModalTransitionStylePartialCurl // 翻页。


2、设置弹出控制器的风格(即呈现样式,最终显示的样子),通过modalPresentationStyle属性来设置

//跳转之后覆盖整个屏幕,不透明UIModalPresentationFullScreen = 0     //跳转之后覆盖整个屏幕,不透明UIModalPresentationPageSheet     //跳转之后覆盖整个屏幕,不透明UIModalPresentationFormSheet     //跳转之后覆盖当前内容(除导航栏和标签栏部分),不透明UIModalPresentationCurrentContext     //跳转之后显示自定制视图(默认是覆盖整个屏幕),可以透明UIModalPresentationCustom     //跳转之后覆盖整个屏幕,可以透明UIModalPresentationOverFullScreen     //跳转之后覆盖当前内容(除导航栏和标签栏部分),可以透明UIModalPresentationOverCurrentContext     //跳转之后覆盖整个屏幕,不透明UIModalPresentationPopover

举个栗子

TwoViewController *twoVc = [[TwoViewController alloc] init];//把当前控制器作为背景self.definesPresentationContext = YES;twoVc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;twoVc.modalPresentationStyle = UIModalPresentationOverCurrentContext;    [self presentViewController:twoVc animated:YES completion:nil];

3、定制模态跳转

TwoViewController *twoVc = [[TwoViewController alloc] init];    //创建动画    CATransition * transition = [CATransition animation];        //设置动画类型(这个是字符串,可以搜索一些更好看的类型)    transition.type = @"cube";        //动画出现类型,动画的方向    transition.subtype = @"fromCenter";        //动画时间    transition.duration = 0.3;        //移除当前window的layer层的动画    [self.view.window.layer removeAllAnimations];        //将定制好的动画添加到当前控制器window的layer层    [self.view.window.layer addAnimation:transition forKey:nil];        [self presentViewController:twoVc animated:NO completion:nil];

动画类型type的其它参数

设置动画的属性fade        交叉淡化过渡push        新视图把旧视图推出去moveIn      新视图移到旧视图上面reveal      将旧视图移开,显示下面的新视图cube        立方体翻滚效果-----好oglFlip     上下左右翻转效果---好suckEffect      收缩效果,如一块布被抽走---好rippleEffect    水滴效果-----好pageCurl        向上翻页效果pageUnCurl      向下翻页效果cameraIrisHollowOpen        相机镜头打开效果cameraIrisHollowClose       相机镜头关闭效果


二、自定义转场动画

有3种类型,需要用到如下三个协议:

1、UINavigationControllerDelegate - 自定义navigationController转场动画的时候

2、UITabBarControllerDelegate - 自定义tabbarController转场动画的时候

3、UIViewControllerTransitioningDelegate - 自定义present / dismiss的时候

后续研究,参考博客:

https://onevcat.com/2013/10/vc-transition-in-ios7/

http://www.jianshu.com/p/73e65b70340e