背景
苹果在9月13号凌晨(北京时间)发布 iOS 16,该系统的设备可能会因为各种原因,导致功能不可用和UI错乱等问题,我们需要做好适配iOS 16。
前置条件
开发者对 iOS 16 模拟器和真机调试的前置条件:
UIDevice (屏幕旋转)
-
[New Features] iOS apps can now request rotation using?[UIWindowScene requestGeometryUpdate:errorHandler:]?and providing a?UIWindowSceneGeometryPreferencesIOS?object containing the desired orientations. (95229615) -
[Deprecations][UIViewController shouldAutorotate]?has been deprecated is no longer supported.?[UIViewController attemptRotationToDeviceOrientation]?has been deprecated and replaced with?[UIViewController setNeedsUpdateOfSupportedInterfaceOrientations].
iOS16 横竖屏切换适配
经测试,目前使用UIDevice setValue和attemptRotationToDeviceOrientation配合使用来旋转屏幕是没问题的,但是attemptRotationToDeviceOrientation 是即将废弃的(未来某个版本可能会不可用),推荐用shouldAutorotateToInterfaceOrientation替代shouldAutorotate,用setNeedsUpdateOfSupportedInterfaceOrientations替换attemptRotationToDeviceOrientation。
setNeedsUpdateOfSupportedInterfaceOrientations和[UIWindowScene requestGeometryUpdate:errorHandler:]需要在Xcode 14和#available(iOS 16.0, *)环境才能编译
使用?UIDevice.current.setValue(value, forKey: "orientation"),真机环境调试 iOS 16,旋转屏幕控制台会收到警告:
2022-09-15 17:52:57.588159+0800 italki[7177:1083152] [Orientation] BUG IN CLIENT OF UIKIT: Setting UIDevice.orientation is not supported. Please use UIWindowScene.requestGeometryUpdate(_:)
UIScreen
-
@property(class, nonatomic, readonly) UIScreen *mainScreen API_DEPRECATED("Use a UIScreen instance found through context instead: i.e, view.window.windowScene.screen", ios(2.0, API_TO_BE_DEPRECATED)); // the device's internal screen
UIScreen.main即将被废弃,建议使用(UIApplication.shared.connectedScenes.first as? UIWindowScene)?.screen
UISearchBarController
从iOS16起,UISearchBar在iPad上发生了变化,在导航栏的右边,Cancel按钮没有居中。

其他新特性
?参考文献
What's new in UIKit - WWDC22 - Videos - Apple Developer
Apple Developer Documentation
iOS16 适配指南 - 掘金
iOS16适配指南之UINavigationItem - 掘金
iOS16适配指南之LARightStore - 简书
iOS16适配指南之UIFindInteraction - 掘金
iOS16适配指南之UIEditMenuInteraction - 掘金
Apple Developer Documentation
??????iOS16 横竖屏切换适配
|