gpt4 book ai didi

swift - iOS 13 Modals - 以编程方式调用滑动解除

转载 作者:行者123 更新时间:2023-12-03 09:28:34 25 4
gpt4 key购买 nike

我想在呈现模态的 View Controller 中检测模态解除。

这种方法对于检测新的卡片模式上的新 iOS 13 滑动解除非常有效:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "MyIdentifier" {
segue.destination.presentationController?.delegate = self
}
}

extension MyController: UIAdaptivePresentationControllerDelegate {
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
//clean up UI (de-selecting stuff) once modal has been dismissed
}
}

但是,如果模态通过操作以编程方式自行关闭,则不会调用presentationControllerDidDismiss:
@IBAction func btnDismissTap(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}

这是一个错误还是有一种方法可以以编程方式调用任何“滑动”解除,以便我可以以相同的方式检测所有解除?目前,我正在将额外的“解雇”委托(delegate)方法写入我的模式作为解决方法,这似乎没有必要。

最佳答案

However, presentationControllerDidDismiss is NOT called if the modal dismisses itself programmatically through an action

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


不需要调用它,因为您自己在代码中解除了模式。您不能不知道模态已被解雇。您不需要接收解雇信号,因为您首先给出了解雇信号。

您通常不会收到委托(delegate)方法调用报告您自己的代码所做的事情。委托(delegate)方法报告用户操作。如果您自己在代码中所做的一切都以委托(delegate)方法调用的形式返回,那就太疯狂了。

关于swift - iOS 13 Modals - 以编程方式调用滑动解除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57941872/

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