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
相关推荐
非专业程序员Ping6 小时前
一文读懂字体文件
ios·swift·assembly·font
wahkim10 小时前
移动端开发工具集锦
flutter·ios·android studio·swift
2501_9160074711 小时前
提升 iOS 26 系统流畅度的实战指南,多工具组合监控
android·macos·ios·小程序·uni-app·cocoa·iphone
hellojackjiang201113 小时前
全面适配iOS 26液态玻璃,基于开源IM即时通讯框架MobileIMSDK:RainbowChat-iOS端v10.2发布
ios·网络编程·即时通讯·im开发·rainbowchat
非专业程序员Ping16 小时前
一文读懂字符、字形、字体
ios·swift·font
2501_9159214317 小时前
iOS 应用代上架流程,多工具组合与使用 开心上架 跨平台自动化上传指南
android·ios·小程序·uni-app·自动化·cocoa·iphone
日日行不惧千万里17 小时前
2025最新仿默往 IM 即时通讯系统源码(PC + Web + iOS + Android)完整版发布!
android·ios
歪歪10017 小时前
React Native开发Android&IOS流程完整指南
android·开发语言·前端·react native·ios·前端框架
阿里超级工程师19 小时前
ios云打包证书申请不需要苹果电脑也是可以的
ios·证书·云打包
2501_9159184120 小时前
iOS 混淆与 IPA 加固一页式行动手册(多工具组合实战 源码成品运维闭环)
android·运维·ios·小程序·uni-app·iphone·webview