gpt4 book ai didi

ios - 如何在 iOS 13 中查看和弹出 View Controller

转载 作者:行者123 更新时间:2023-12-02 04:37:34 24 4
gpt4 key购买 nike

Peek 和 pop (UIViewControllerPreviewing) 在 iOS 13 中已弃用。它将被新的 contextMenuInteraction 内容取代。

那么如何直接替换peek和pop呢?换句话说,如何将目标 View Controller 显示为预览(查看),然后让用户从那里弹出到实际目标 View Controller 的呈现?

这是我正在尝试的,但它与旧的 peek 和 pop 不同:

override func viewDidLoad() {
super.viewDidLoad()
let inter = UIContextMenuInteraction(delegate: self)
self.view.addInteraction(inter)
}

func contextMenuInteraction(_ inter: UIContextMenuInteraction,
configurationForMenuAtLocation loc: CGPoint) -> UIContextMenuConfiguration? {
let config = UIContextMenuConfiguration(identifier: "preview" as NSString,
previewProvider: { SecondViewController() }, actionProvider: nil)
return config
}

func contextMenuInteraction(_ interaction: UIContextMenuInteraction,
willCommitWithAnimator animator: UIContextMenuInteractionCommitAnimating) {
// animator.preferredCommitStyle = .pop
if let vc = animator.previewViewController {
animator.addCompletion {
self.present(vc, animated: true, completion: nil)
}
}
}

在这个简单的测试中,第一个 View Controller 的整个背景 View 变成了我们可以长按以查看第二个 View Controller 的预览的地方。所发生的情况是,我们确实看到了预览,并且用户可以点击它。但随后预览被取消,然后出现第二个 View Controller 。

这不是偷看和流行。 Peek and pop 意味着预览成为第二个 View Controller 。它应该成长成为演示文稿(“pop”)。

我尝试将动画师的 preferredCommitStyle 设置为 .pop (如注释行所示),但没有任何区别。

有人解决了吗?

编辑 Apple自己的应用程序也不能正确执行此操作。在“照片”应用程序中,如果长按照片以获取上下文菜单和预览,如果点击预览,预览将被取消,然后推送的图像会突然出现。此外,如果您随后尝试返回(点击后退按钮),则会崩溃。

最佳答案

这个问题是在 iOS 13 Beta 开发的早期阶段提出的。我提交了错误报告。事实证明,我所看到的一个错误,而苹果公司也知道这一点。在 iOS 13 Beta 开发的后期阶段,实现了正确的 .pop 行为,事实上是默认行为。因此,它现在的外观和行为就像早期系统中的 peek 和 pop 一样。

所以,在我的问题中,我说:

That's not peek and pop. Peek and pop means the preview becomes the second view controller. It should grow to become the presentation ("pop").

这就是它现在所做的。该错误已修复,问题也已解决(我已向 Apple 关闭了我的错误报告)。

关于ios - 如何在 iOS 13 中查看和弹出 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57451890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com