iOS26适配指南之UIViewController

介绍

WWDC24 中 UIViewController 增加了 5 种特殊的转场效果zoomcoverVerticalflipHorizontalcrossDissolvepartialCurl。但是触发条件仅限于 UIView,WWDC25 将zoom的触发条件扩展至 UIBarButtonItem。

使用

  • 代码。
swift 复制代码
import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let barButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(barButtonItemClicked))
        navigationItem.rightBarButtonItem = barButtonItem
    }

    @objc func barButtonItemClicked(_ sender: Any) {
        let nextViewController = NextViewController()
        nextViewController.view.backgroundColor = .systemRed
        nextViewController.preferredTransition = .zoom { context in
            guard context.zoomedViewController is NextViewController else {
                fatalError("Unable to access the current UIViewController.")
            }
            // iOS26新增,返回触发的UIBarButtonItem
            return self.navigationItem.rightBarButtonItem
        }
        present(nextViewController, animated: true)
    }
}

class NextViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .systemGreen
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        dismiss(animated: true)
    }
}
  • 效果。
相关推荐
CareyWYR41 分钟前
安康记1.1.x版本发布
ios·app
岁月向前2 小时前
SwiftUI和UIKit区别
ios
非专业程序员3 小时前
iOS 实现微信读书的仿真翻页
ios·swiftui·swift
非专业程序员Ping5 小时前
iOS 实现微信读书的仿真翻页
ios·swiftui·swift
AirDroid_cn12 小时前
iPhone 的5G 信号弱时,如何强制切换为4G?
5g·ios·iphone
用户1972959188911 天前
WKWebView的重定向(objective_c)
前端·ios
lancoff1 天前
#3 Creating Shapes in SwiftUI
ios·swiftui
lancoff1 天前
#1 How to use Xcode in SwiftUI project
ios·swiftui
lancoff1 天前
#2 Adding Text in SwiftUI
ios·swiftui
良逍Ai出海1 天前
Build in Public|为什么我开始做一款相册清理 App(听说有竞品年收益40W)
ios·uni-app·ai编程·coding