gpt4 book ai didi

iOS Popover 在关闭后不会消失

转载 作者:行者123 更新时间:2023-11-28 13:55:07 32 4
gpt4 key购买 nike

我们有一个 View Controller ,在单击时显示来自 UIBarButtonItem 的弹出窗口。弹出窗口显示正常,但当我们单击弹出窗口内的取消按钮时,它会调用 dismiss(_:completion:),或者当我们点击弹出窗口外部时,弹出窗口消失。但是,呈现弹出窗口的 View Controller 内的所有内容仍然不可点击。当我们检查 View 层次结构时,我们可以看到弹出窗口及其 UITrasitionView 仍在窗口上并阻止其后面的 View Controller ,即使在模拟器中弹出窗口不再可见。可能是什么原因?

我们已经正确设置了弹出框 Controller 的 buttonBarItem 并且它正确显示了。只是当它被驳回时,问题就来了。

代码看起来像这样:

let controller = SettingsController() // the settings controller
controller.popoverPresentationController?.barButtonItem = sender // the UIBarButtonItem
self.present(controller, animated: true, completion: nil)

即使我们用普通的 UIViewController 替换 SettingsController 也没有任何改变。

附言这个显示 View Controller 的 View Controller 使用自定义转换,但在检查带有断点的代码后,我们认为这不是自定义转换委托(delegate)不参与弹出窗口的显示/关闭的原因。

最佳答案

打开 View

let vc = SettingsController()
vc.modalPresentationStyle = .overCurrentContext
let nav = UINavigationController(rootViewController: vc)
self.present(nav, animated: true, completion: nil)

关闭 View

self.dismiss(animated: true, completion: nil)

关于iOS Popover 在关闭后不会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53984026/

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