gpt4 book ai didi

swift - 除了帮助 iOS 中的特征收集外,UIPresentationController 还需要什么?

转载 作者:行者123 更新时间:2023-11-28 11:05:20 24 4
gpt4 key购买 nike

UIPresentationController 与仅使用添加 subview 和动画化您想要呈现的 View 相比有什么好处?它必须遵守的所有协议(protocol)似乎有点麻烦,许多人仍然喜欢用简单的帧动画来呈现他们的 View 。 Apple 引入该类(class)的逻辑是什么?

最佳答案

早在 UIPresentationController 被引入之前,Presentation machinery 就是 UIKit 的一部分。 UIPresentationController 提供了更大的灵 active ,并允许创建与内置演示不同的自定义演示(全屏、当前上下文、弹出窗口等)。存在表示机制和 UIPresentationController 的原因有很多:

  • 管理 View 层次结构。每当你想呈现 View 时,你并不总是拥有呈现 View Controller 。通常不鼓励干扰你不拥有的 View Controller 的子层次结构,但在演示的情况下,你需要添加 presented View Controller 的 View 作为 呈现 View Controller 的 View (或其父 View )。当涉及上下文中的呈现链时,它会变得更加复杂(例如弹出窗口 -> 当前上下文 -> 共享表)。当使用表示机制时,UIKit 以一致的方式负责 View 层次结构管理。它还为 UIPresentationController 类建立了一个容器 View ,让它专注于只管理参与演示的 View 。 UIPresentationController 类可以选择向容器 View 添加任意装饰和阴影 View ,并响应 containerViewWillLayoutSubviews 方法中的布局更改。
  • 管理模式。 View Controller 以非常特定的顺序呈现和关闭,呈现 Controller API 强制执行此操作。演示机制还确保对于被演示模糊的 View 禁用交互。
  • 维护 View Controller 层次结构。呈现 Controller 可以被视为一种更具体的 View Controller 包含类型,它们确保呈现的 View Controller 仍然是 View Controller 层次结构的一部分。这对于特征集合传播、外观回调、发送 viewWillTransitionToSize:withTransitionCoordinator:、执行 View Controller 转换(包括嵌套演示)等等都是必需的。
  • 管理急救人员。当演示发生时,当前的第一响应者被隐藏起来,然后在解雇后恢复。

关于swift - 除了帮助 iOS 中的特征收集外,UIPresentationController 还需要什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38050695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com