iOS17适配指南之其他细节

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)
    }
}

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)
    }
}

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)
    }
}

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)
            }
        }
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 啰嗦一句 之前使用的博客系统似乎要停掉了, 自己经常会记录一些易忘记的代码片段, 还是拷贝到简书来吧...简书不支...
    旭丶Joy阅读 728评论 0 1
  • 代码注释不能用的解决办法这个是因为苹果解决xcode ghost,把插件屏蔽了。解决方法打开终端,命令运行: su...
    762683ff5d3d阅读 1,034评论 0 0
  • 1. 事件传递与响应者链? 首先只有继承了UIResponder的对象才能接收并处理事件,事件的传递是从上到下(父...
    飞哥漂流记阅读 135评论 0 0
  • 一iOS12 1.1升级Xcode10后项目报错 不允许多个info.plist,Xcode10是默认选中的最新的...
    usg阅读 1,430评论 0 0
  • 声明:这篇文章转载 *zombieEngineer * [Cocoa开发者社区]仅供大家参考学习使用,也方便自己...
    追逐_chase阅读 609评论 0 0