iOS 17新特性以及适配细节汇总

打印 上一主题 下一主题

主题 884|帖子 884|积分 2652

1、UIScrollView
增加了属性allowsKeyboardScrolling表示是否根据连接的物理键盘的方向键而滚动。
  1. import UIKit
  2. class ViewController: UIViewController {
  3.     lazy var scrollView: UIScrollView = {
  4.         let scrollView = UIScrollView(frame: CGRect(x: 0,
  5.                                                     y: 0,
  6.                                                     width: UIScreen.main.bounds.width,
  7.                                                     height: UIScreen.main.bounds.width))
  8.         let imageView = UIImageView(image: UIImage(named: "img"))
  9.         scrollView.addSubview(imageView)
  10.         scrollView.contentSize = imageView.bounds.size
  11.         // iOS17新增,默认为true
  12.         scrollView.isScrollEnabled = false
  13.         return scrollView
  14.     }()
  15.     override func viewDidLoad() {
  16.         super.viewDidLoad()
  17.         view.addSubview(scrollView)
  18.     }
  19. }
复制代码
2、applicationIconBadgeNumber
UIApplication 的applicationIconBadgeNumber属性被废弃,建议使用UNUserNotificationCenter.current().setBadgeCount()方法。
  1. import UIKit
  2. import UserNotifications
  3. class ViewController: UIViewController {
  4.     override func viewDidLoad() {
  5.         super.viewDidLoad()
  6.     }
  7.     override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  8.         // iOS17之后设置角标,需要先授权
  9.         // UNUserNotificationCenter.current().setBadgeCount(10)
  10.         UNUserNotificationCenter.current().setBadgeCount(10) { error in
  11.             if let error {
  12.                 print(error)
  13.             }
  14.         }
  15.     }
  16. }
复制代码
3、UIDocumentViewController
新增视图控制器,用于显示与管理本地或者云端文档。
  1. import UIKit
  2. class ViewController: UIViewController {
  3.     override func viewDidLoad() {
  4.         super.viewDidLoad()
  5.     }
  6.     override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  7.         let documentViewController = UIDocumentViewController()
  8.         documentViewController.openDocument { _ in
  9.             print("打开文档")
  10.         }
  11.         present(documentViewController, animated: true)
  12.     }
  13. }
复制代码
4、UIHoverStyle
UIView 增加了一个hoverStyle属性,可以设置鼠标移动到 UIView 之上的效果。
  1. import UIKit
  2. class ViewController: UIViewController {
  3.     lazy var redView: UIView = {
  4.         let view = UIView(frame: CGRect(x: 200, y: 200, width: 200, height: 200))
  5.         view.backgroundColor = .red
  6.         // iOS17新增UIHoverStyle,可以设置Hover的效果与形状(UIShape)
  7.         let hoverStyle = UIHoverStyle(effect: .lift, shape: .capsule)
  8.         // iOS17新增,鼠标移动到UIView之上的效果
  9.         view.hoverStyle = hoverStyle
  10.         return view
  11.     }()
  12.     override func viewDidLoad() {
  13.         super.viewDidLoad()
  14.         view.addSubview(redView)
  15.     }
  16. }
复制代码
5、编译报错cfstring constant not pointer aligned
  1. 解决办法:Build Settings -> Other Linker Flags 加入-ld64
复制代码
6、编译报错Sandbox:rsync.sanba deny(1) file-write-create xxx
  1. 使用 Xcode15 新建项目后,pod 引入部分第三方会报上面的错误
  2. 解决办法:Build Settings 搜索 sandbox,把 Build Options 中的 User Script Sandboxing改为 NO
复制代码
7、编译报错UIGraphicsBeginImageContextWithOptions崩溃
参考链接:UIGraphicsBeginImageContext Deprecated
  1. YYText使用时会崩溃在UIGraphicsBeginImageContextWithOptions<br>
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

农妇山泉一亩田

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表