IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> iOS16适配 -> 正文阅读

[移动开发]iOS16适配

背景

苹果在9月13号凌晨(北京时间)发布 iOS 16,该系统的设备可能会因为各种原因,导致功能不可用和UI错乱等问题,我们需要做好适配iOS 16。

前置条件

开发者对 iOS 16 模拟器和真机调试的前置条件

  • 需要安装?Xcode 14 或者下载真机调试包

  • 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 setValueattemptRotationToDeviceOrientation配合使用来旋转屏幕是没问题的,但是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按钮没有居中。

其他新特性

  • 新增 UICalendarView,可以显示日期并支持单选与多选日期。

  • 新增 UIPasteControl 用于读取剪贴板中的内容,否则跨 App 读取时会弹出对话框让用户进行选择是否同意。

  • UINavigationItem 变化iOS16适配指南之UINavigationItem - 掘金
    • 增加了一个属性titleMenuProvider用于给当前导航栏的标题添加操作菜单。

      // backAction用于实现当前 UIViewController 的返回按钮事件
      navigationItem.backAction = UIAction(handler: { _ in
          self.navigationController?.popViewController(animated: true)
      })
    • 增加了一个属性backAction用于实现当前 UIViewController 的返回按钮事件;

      // 用于给当前导航栏的标题添加操作菜单
      navigationItem.titleMenuProvider = { _ in
          let favorite = UIAction(title: "Favorite", image: UIImage(systemName: "heart.fill")) { _ in
              print("favorite")
          }
          let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up.fill")) { _ in
              print("share")
          }
          let delete = UIAction(title: "Delete",
                                image: UIImage(systemName: "trash.fill"),
                                attributes: [.destructive]) { _ in
              print("delete")
          }
          return UIMenu(children: [favorite, share, delete])
      }
    • 增加了一个属性style用于描述 UINavigationItem 在 UINavigationBar 上的布局;

      // 设置style
      navigationItem.style = .editor // browser, navigator
    • 隐私权限增强,如通过 UIDevice 获取设备名称时,无法获取用户的信息,只能获取设备对应的名称。

    • UIDevice 不再支持通过setValue()方法设置设备的方向,替换为 UIWindowScene 的requestGeometryUpdate()方法。

    • 新增一个交互 UIEditMenuInteraction,用于取代 UIMenuController 与 UIMenuItem。iOS16适配指南之UIEditMenuInteraction - 掘金

    • 新增一个交互 UIFindInteraction 用于文本内容查找与替换,UITextView、WKWebView 与 PDFView 已经默认支持,但需要将其isFindInteractionEnabled属性设置为true。iOS16适配指南之UIFindInteraction - 掘金

    • 新增 LARightStore 用于存储与获取 keychain 中的数据。iOS16适配指南之LARightStore - 简书

    • UIImage 增加了新的构造函数用于支持 SF Symbols 最新版中增加的类别 Variable。(如Wifi信号图标)

    • UIPageControl 支持垂直显示并可以设置指示器与当前页的图片。

    • UITableView 与 UICollectionView 增加了新的selfSizingInvalidation参数,通过它 Cell 具备自动调整大小的能力。

    • UITableView 与 UICollectionView 在使用 Cell Content Configuration 时支持使用 UIHostingConfiguration 包装 SwiftUI 代码定义 Cell 的内容。

    • cell.contentConfiguration = UIHostingConfiguration {
      ??? HStack {
      ??????? Image(systemName: images[indexPath.row])
      ??????????? .foregroundStyle(.teal)
      ??????? Text(devices[indexPath.row])
      ??????????? .font(.caption)
      ??????????? .foregroundStyle(.secondary)
      ??? }
      }
    • UISheetPresentationController 支持自定义显示的 UIViewController 的大小。

    • UIMenu 支持设置尺寸,分别为small、medium与large。

    • let addNewMenu = UIMenu(title: "", preferredElementSize: .small, children: menuActions)
    • 支持 Live Activity,可以理解为一种特殊的锁屏界面显示的 Widget。

?参考文献

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 横竖屏切换适配

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2022-09-30 01:04:20  更:2022-09-30 01:04:39 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/19 23:18:59-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码