模态

作者: wpf_register | 来源:发表于2020-01-17 12:21 被阅读0次

原文链接

iOS中显示ViewController的方式有两种push和modal,modal也叫模态,其主要用于有以下场景:

  • 收集用户输入信息
  • 临时呈现一些内容
  • 临时改变工作模式
  • 显示一个新的view层级

presenting view controller / presented view controller

当vcA模态的弹出了vcB,那么VCA就是presenting view controller,
VCB就是presented view controller

[vcA presentViewController:vcB animated:YES completion:nil];

container view controller

container view controller 指的是VC的容器类,
通过container view controller,我们可以很方便的管理子VC,
实现VC之间的跳转等。
iOS中container view controller包括 UINavigation Controller, UISplitView Controller, 以及 UIPageViewController.

ModalPresentationStyle

  • UIModalPresentationCustom
    自定义模式,需要实现UIViewControllerTransitioningDelegate的相关方法,并将presented VC的transitioningDelegate 设置为实现了UIViewControllerTransitioningDelegate协议的对象

  • UIModalPresentationPageSheet
    在常规型设备(大屏手机,例如plus系列以及iPad系列)的水平方向,presented VC的高为当前屏幕的高度,宽为该设备竖直方向屏幕的宽度,其余部分用透明背景做填充。对于紧凑型设备(小屏手机)的水平方向及所有设备的竖直方向,其显示效果与UIModalPresentationFullScreen相同。

  • UIModalPresentationFormSheet
    在常规型设备的水平方向,presented VC的宽高均小于屏幕尺寸,其余部分用透明背景填充。对于紧凑型设备的水平方向及所有设备的竖直方向,其显示效果与UIModalPresentationFullScreen相同

  • UIModalPresentationFullScreen
    使用这种模式时,presented VC的宽高与屏幕相同,
    并且UIKit会直接使用rootViewController做为presentation context,此次presentation完成之后 UIKit会将presentation context及其子VC都移出UI栈,这时候观察VC的层级关系,会发现UIWindow下只有presented VC。

  • UIModalPresentationOverFullScreen
    与UIModalPresentationFullScreen的唯一区别在于,UIWindow下除了presented VC,还有其他正常的VC层级关系。该模式下,UIKit以rootViewController为presentation context,但presentation完成之后不会将rootViewController移出当前的UI栈。

  • UIModalPresentationCurrentContext
    使用这种方式presentVC时,presentedVC的宽高取决于presentation context宽高,并且UIKit会寻找属性definesPresentationContext为YES的VC,作为presentation context,具体的寻找方式会在下文中给出 。当此次presentation完成之后,presentation context及其子VC都将被暂时移出当前的UI栈。

  • UIModalPresentationOverCurrentContext
    寻找presentation context的方式与UIModalPresentationCurrentContext相同,所不同的是presentation完成之后,不会将context及其子VC移出当前UI栈。但是,这种方式只适用于transition style为UIModalTransitionStyleCoverVertical的情况(UIKit默认就是这种transition style)。其他transition style下使用这种方式将会触发异常

UIModalTransitionStyle

  • UIModalTransitionStyleCoverVertical
  • UIModalTransitionStyleFlipHorizontal
  • UIModalTransitionStyleCrossDissolve

presentation context

presentation context是指为本次present提供上下文环境的类,
需要指出的是,presenting VC通常并不是presentation context,
当我们需要present VC的时候,除非我们指定了context,
否则UIKit会优先选择presenting VC所属的容器类做为presentation context,如果没有容器类,那么会选择rootViewController。

注意,UIKit搜索context的方式还与presented VC的modalPresentationStyle属性有关,当modalPresentationStyle为UIModalPresentationFullScreen或UIModalPresentationOverFullScreen等模式时,UIKit会直接选择rootViewController做为context。

当modalPresentationStyle为UIModalPresentationOverCurrentContext及UIModalPresentationCurrentContext模式时,UIKit搜索context的方式如下:
一个VC能否成为presentation context 是由VC的definesPresentationContext属性决定的,这是一个BOOL值,默认UIViewController的definesPresentationContext属性值是NO,而 container view controller的definesPresentationContext默认值是YES。

这也是上文中,UIKit总是将container view controller做为presentation context的原因。如果我们想指定presenting VC做为context,只需要在presenting VC的viewDidLoad方法里添加如下代码即可:

self.definesPresentationContext = YES

当然,还有另外一种特殊情况,当我们在一个presented VC上再present一个VC时,UIKit会直接将这个presented VC做为presentation context。

相关文章

  • 产品页面设计--控件规范

    一、模态与非模态 模态:模态控件必须进行操作之后才可以进行其他界面操作。 非模态:非模态控件的出现不影响用户继续界...

  • 模态弹出

    1、模态弹出2、模态返回 有时候不用不写,还真是想不到怎么做一、模态弹出这是在UIView里面弹出模态,因为模态只...

  • 进阶任务10-事件应用

    实现Tab切换的功能 实现下图的模态框功能,点击模态框不隐藏,点击关闭以及模态框以外的区域模态框隐藏

  • 移动端弹窗的分类与介绍

    一、分类 主要分为 模态弹窗 和 非模态弹窗 两大类 1. 模态弹窗————用户必须进行操作回应 2. 非模态弹窗...

  • 多模态机器学习

    多模态学习可以划分为以下五个研究方向: 多模态表示学习 Multimodal Representation 单模态...

  • 第十三节 MFC的一些概念

    一、模态对话框和非模态对话框Windows对话框分为两类:模态对话框和非模态对话框。模态对话框是这样的对话框,当它...

  • element-ui dialog组件嵌套bug

    模态框嵌套模态框 只需在子集的模态框里面添加append-to-body 就可以了 父级模框 子集模态框 我这样嵌...

  • bootstrap模态框多层嵌套,背景滚动

    问题:在弹出模态框A的基础上,弹出模态框B,关闭模态框B之后,模态框A不能滚动(由于A模块框内容) 造成的原因:遮...

  • modal 模态框

    Modal 模态框 标签(空格分隔): modal 什么叫做模态框 modal: adj.模态的;形态上的;情态的...

  • 超过三百套MB电磁式模态激振系统应用分析_瑞世佳华

    实验模态分析或模态测试是物理获取结构动态特性数据模型的过程。模态测试可得到结构的模态参数:固有频率、振型、质量、刚...

网友评论

      本文标题:模态

      本文链接:https://www.haomeiwen.com/subject/geyczctx.html