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

1、UIScrollView
增加了属性 allowsKeyboardScrolling表示是否根据连接的物理键盘的方向键而滚动。

复制代码
import UIKit

class ViewController: UIViewController {
    lazy var scrollView: UIScrollView = {
        let scrollView = UIScrollView(frame: CGRect(x: 0,
                                                    y: 0,
                                                    width: UIScreen.main.bounds.width,
                                                    height: UIScreen.main.bounds.width))
        let imageView = UIImageView(image: UIImage(named: "img"))
        scrollView.addSubview(imageView)
        scrollView.contentSize = imageView.bounds.size
        // iOS17新增,默认为true
        scrollView.isScrollEnabled = false
        return scrollView
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(scrollView)
    }
}

2、applicationIconBadgeNumber

UIApplication 的applicationIconBadgeNumber属性被废弃,建议使用UNUserNotificationCenter.current().setBadgeCount()方法。

复制代码
import UIKit
import UserNotifications

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        // iOS17之后设置角标,需要先授权
        // UNUserNotificationCenter.current().setBadgeCount(10)
        UNUserNotificationCenter.current().setBadgeCount(10) { error in
            if let error {
                print(error)
            }
        }
    }
}

3、UIDocumentViewController

新增视图控制器,用于显示与管理本地或者云端文档。

复制代码
import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        let documentViewController = UIDocumentViewController()
        documentViewController.openDocument { _ in
            print("打开文档")
        }
        present(documentViewController, animated: true)
    }
}

4、UIHoverStyle

UIView 增加了一个hoverStyle属性,可以设置鼠标移动到 UIView 之上的效果。

复制代码
import UIKit

class ViewController: UIViewController {
    lazy var redView: UIView = {
        let view = UIView(frame: CGRect(x: 200, y: 200, width: 200, height: 200))
        view.backgroundColor = .red
        // iOS17新增UIHoverStyle,可以设置Hover的效果与形状(UIShape)
        let hoverStyle = UIHoverStyle(effect: .lift, shape: .capsule)
        // iOS17新增,鼠标移动到UIView之上的效果
        view.hoverStyle = hoverStyle
        return view
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(redView)
    }
}

5、编译报错cfstring constant not pointer aligned

复制代码
解决办法:Build Settings -> Other Linker Flags 加入-ld64

6、编译报错Sandbox:rsync.sanba deny(1) file-write-create xxx

复制代码
使用 Xcode15 新建项目后,pod 引入部分第三方会报上面的错误
解决办法:Build Settings 搜索 sandbox,把 Build Options 中的 User Script Sandboxing改为 NO

7、编译报错UIGraphicsBeginImageContextWithOptions崩溃

参考链接:UIGraphicsBeginImageContext Deprecated

复制代码
YYText使用时会崩溃在UIGraphicsBeginImageContextWithOptions
相关推荐
ZZH_AI项目交付27 分钟前
同一套前摄心率算法,为什么 iPhone 16 Pro 稳,iPhone XR 会失准?
ios·app·ai编程
DeMinds1 小时前
内容没有丢,我为什么总在重新整理?|DeMinds 如何让工作接着继续
ios·github·markdown
apd_csdn1 小时前
清华邮箱苹果邮件app设置(全)
ios·thu
MDM.Plus2 小时前
从“遥控”到“自治”:苹果 MDM 技术的代际跨越与业务重构
ios·智能手机·重构·mdm
黑化旺仔3 小时前
iOS - 天气预报仿写总结
ios
Coffeeee4 小时前
ios零基础的Android开发能否靠AI让老板省一笔人工费呢
android·ios·ai编程
2501_916007474 小时前
深入理解HTTPS对称与非对称加密机制及Charles抓包实践
网络协议·http·ios·小程序·https·uni-app·iphone
2501_916008894 小时前
HTTPS 抓包遇到证书绑定怎么办,使用 TraceEagle 解除 App 证书校验
网络协议·计算机网络·http·网络安全·ios·adb·https
2501_915921436 小时前
从零开始学 Swift iOS 开发 iOS应用入门
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
末代iOS程序员华仔6 小时前
Swift 的角色演变:从“主角”到“最佳配角”——iOS 应用被 Flutter 替换,Swift 变成辅助?
flutter·ios·swift