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
相关推荐
2501_9159214321 小时前
uni-app 的 iOS 打包与上架流程,多工具协作
android·ios·小程序·uni-app·cocoa·iphone·webview
胖虎11 天前
SwiftUI 页面作为一级页面数据被重置问题分析
ios·swiftui·swift·state·observedobject·stateobject·swiftui页面生命周期
健了个平_241 天前
【iOS】如何在 iOS 26 的UITabBarController中使用自定义TabBar
ios·swift·wwdc
Digitally2 天前
无需 iTunes 将文件从 PC 传输到 iPhone
ios·iphone
1024小神2 天前
xcode 配置了AppIcon 但是不显示icon图标
ios·swiftui·swift
2501_915918412 天前
iOS 项目中证书管理常见的协作问题
android·ios·小程序·https·uni-app·iphone·webview
ITKEY_2 天前
iOS网页应用无地址栏无工具栏
ios
2501_915918412 天前
提升 iOS 应用安全审核通过率的一种思路,把容易被拒的点先处理
android·安全·ios·小程序·uni-app·iphone·webview
RollingPin2 天前
iOS探究使用Block方式实现一对多回调能力
ios·block·runtime·数据分发·解耦·动态绑定·一对多回调
TheNextByte12 天前
iPhone短信备份与恢复:3种最佳方法及短信备份与恢复应用
ios·iphone