前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS17适配指南之其他细节

iOS17适配指南之其他细节

作者头像
YungFan
发布2023-09-01 17:45:20
9000
发布2023-09-01 17:45:20
举报
文章被收录于专栏:学海无涯学海无涯

UIDocumentViewController

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

代码语言:javascript
复制
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)
    }
}

UIHoverStyle

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

代码语言:javascript
复制
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)
    }
}

UIScrollView

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

代码语言:javascript
复制
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)
    }
}

applicationIconBadgeNumber

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

代码语言:javascript
复制
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)
            }
        }
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-08-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • UIDocumentViewController
  • UIHoverStyle
  • UIScrollView
  • applicationIconBadgeNumber
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档