首先是UIPresentationController,这个控制器给modal新的viewController提供了下一步的view和转场的管理,从一个viewController被modal出来到被dismiss,都是用UIPresentationController来管理视图被展现的过程的各个方面。可以添加自定义动画,对大小改变做出响应,并且可以管理其他viewController是如何显示在屏幕的。
在初始化时,重写
这个只读属性是被呈现的视图所在的view,我们可以在这个view上添加其他视图,通过
insertSubview(dummyView, atIndex: 0)这个方法。
接下来就用到两个代理 UIViewControllerTransitioningDelegate和 UIViewControllerAnimatedTransitioning
实现代理方法,isPresented是一个是否被呈现的标记
// 返回负责转场的控制器对象
func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {
return PopoverPresentationController(presentedViewController: presented, presentingViewController: presenting)
} // 返回提供modal动画的对象
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
isPresented = true
return self
} // 返回提供dismiss动画的对象
func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
isPresented = false
return self
} // 动画时长
func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return 1.2
} // 转场动画实现函数
func animateTransition(transitionContext: UIViewControllerContextTransitioning) { }
在最后一个方法中实现转场动画的过程。
此外,还要设置
// 设置转场动画代理
vc.transitioningDelegate = self
// 将转场动画设置为自定义
vc.modalPresentationStyle = UIModalPresentationStyle.Custom
否则,转场动画是无法自定义的。

最新文章

  1. 利用keepalived和haproxy配置mysql的高可用负载均衡
  2. USVN
  3. 1不等于1?numeric、decimal、float 和 real 数据类型的区别
  4. vi和vim 的常用操作
  5. 【转载】Lucene.Net入门教程及示例
  6. (转) linux之sort用法
  7. Android常见控件— — —ProgressDialog
  8. Install Oracle Java JDK/JRE 7u55 on Fedora 20/19, CentOS/RHEL 6.5/5.10
  9. Android网络通信库Volley简介
  10. Spring MVC的启动过程
  11. Sublime text 取消记住上一次打开的,这功能太墨迹了!
  12. Myeclipse 中添加mysql的jdbc驱动
  13. Database(Mysql)发版控制二
  14. 实战nginx 基础知识总结(一)1.1
  15. groupbox 下的datagridview的列标题字体修改混乱
  16. 关于xmlHttp.status最新统计
  17. How to setup a DL4J project with eclipse
  18. 痞子衡嵌入式:并行接口NAND标准(ONFI)及SLC Raw NAND简介
  19. 【读书笔记】iOS-解析XML
  20. Linux定时任务调度

热门文章

  1. Hexo博客框架
  2. yum 安装 nfs,rpcbind 出现错误 libc.so.6(GLIBC_2.14)(64bit) is needed by
  3. vue框架-学习记录
  4. JavaScript对象创建的几种方式
  5. centos/linux下的安装mysql
  6. 关于Properties类常用的操作
  7. Flask從入門到入土(二)——請求响应與Flask扩展
  8. 业余草分享100套精选1000G架构师资料课程(超1T的IT学习资料免费送)
  9. EmguCV中图像类型进行转换
  10. POJ - 2492 种类并查集