publicprotocolUITraitEnvironment : NSObjectProtocol {
@available(iOS8.0, *)
var traitCollection: UITraitCollection { get }
/** To be overridden as needed to provide custom behavior when the environment's traits change. */@available(iOS8.0, *)
functraitCollectionDidChange( _previousTraitCollection: UITraitCollection?)
大家可能早已习惯直接使用 UIScreen.main.bounds。这在过去的一台设备只有唯一屏幕、一个屏幕只有唯一应用情况下是没有问题的。但事情正在发生改变:在 iPadOS 上,一个屏幕已经能显示多个应用了,在 Apple Silicon Mac 上,一个设备也能有多个显示内容不一样的屏幕,应用并不一定会在 UIScreen.main 上显示。
我们应该遵循的原则是:在每个 UIView 中,获取自身的 bounds 属性,或者利用元素间的相对关系 Auto Layout 进行布局。应该尽量避免获取设备本身的宽高来进行布局。
publicprotocolUISplitViewControllerDelegate {
// Return the view controller which is to become the primary view controller after `splitViewController` is collapsed due to a transition to// the horizontally-compact size class. If you return `nil`, then the argument will perform its default behavior (i.e. to use its current primary view// controller).@available(iOS8.0, *)
optionalfuncprimaryViewController(forCollapsingsplitViewController: UISplitViewController) -> UIViewController?
// Return the view controller which is to become the primary view controller after the `splitViewController` is expanded due to a transition// to the horizontally-regular size class. If you return `nil`, then the argument will perform its default behavior (i.e. to use its current// primary view controller.)@available(iOS8.0, *)
optionalfuncprimaryViewController(forExpandingsplitViewController: UISplitViewController) -> UIViewController?
// This method is called when a split view controller is collapsing its children for a transition to a compact-width size class. Override this// method to perform custom adjustments to the view controller hierarchy of the target controller. When you return from this method, you're// expected to have modified the `primaryViewController` so as to be suitable for display in a compact-width split view controller, potentially// using `secondaryViewController` to do so. Return YES to prevent UIKit from applying its default behavior; return NO to request that UIKit// perform its default collapsing behavior.@available(iOS8.0, *)
optionalfuncsplitViewController( _splitViewController: UISplitViewController, collapseSecondarysecondaryViewController: UIViewController, ontoprimaryViewController: UIViewController) -> Bool// This method is called when a split view controller is separating its child into two children for a transition from a compact-width size// class to a regular-width size class. Override this method to perform custom separation behavior. The controller returned from this method// will be set as the secondary view controller of the split view controller. When you return from this method, `primaryViewController` should// have been configured for display in a regular-width split view controller. If you return `nil`, then `UISplitViewController` will perform// its default behavior.@available(iOS8.0, *)
optionalfuncsplitViewController( _splitViewController: UISplitViewController, separateSecondaryFromprimaryViewController: UIViewController) -> UIViewController?