网站首页 全球最实用的IT互联网站!

人工智能P2P分享Wind搜索发布信息网站地图标签大全

当前位置:诺佳网 > 软件工程 > 后端开发 > Swift >

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

时间:2023-09-14 17:44

人气:

作者:admin

标签:

导读:1、UIScrollView增加了属性allowsKeyboardScrolling表示是否根据连接的物理键盘的方向键而滚动。 import UIKit class ViewController: UIViewController { lazy var scrollView: UIScrollVie...
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

分享链接:

工作之余,开了一个淘宝小店,分别销售日常必备生活用品,期待您的光临!点击下图,跳转店铺首页!

上一篇:

下一篇:没有了

温馨提示:以上内容整理于网络,仅供参考,如果对您有帮助,留下您的阅读感言吧!
相关阅读
  • iOS 17新特性以及适配细节汇总

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

    1、UIScrollView增加了属性allowsKeyboardScrolling表示是否根据连接的物理键盘的方向键...
  • 最近几天

    最近几天

    8.03周四 一大早电话吵醒,着急给我妈送卡,早上坐车去延安,顺便下来玩玩,...
本类排行
相关标签
本类推荐

CPU | 内存 | 硬盘 | 显卡 | 显示器 | 主板 | 电源 | 键鼠 | 网站地图

Copyright © 2025-2035 诺佳网 版权所有 备案号:赣ICP备2025066733号
本站资料均来源互联网收集整理,作品版权归作者所有,如果侵犯了您的版权,请跟我们联系。

关注微信