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


    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

    解决办法: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

    YYText使用时会崩溃在UIGraphicsBeginImageContextWithOptions
    
  • 相关阅读:
    Java版工程行业管理系统源码-专业的工程管理软件-提供一站式服务
    网络安全系列-四十五: DNS协议详细讲解
    【机翻】RTnet – 灵活的硬实时网络框架
    ORB-SLAM2 ---- ORBextractor::ORBextractor类
    Docker搭建私有仓库与配置
    SpringBoot启动方式
    Docker Compose
    常用的git命令
    电脑一键重装系统后连不上远程了?教你设置的方法
    独立产品灵感周刊 DecoHack #039 - 制作自己的音乐墙
  • 原文地址:https://blog.csdn.net/Landen2011/article/details/132974825