iOS 13 Modals-以编程方式调用滑动解雇 [英] iOS 13 Modals - Calling swipe dismissal programmatically

查看:139
本文介绍了iOS 13 Modals-以编程方式调用滑动解雇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在呈现模态的视图控制器中检测到模态解雇.

I'd like to detect a modal dismissal in the view controller that's presenting the modal.

此方法对于在新的卡模式上检测到新的iOS 13滑动解雇效果非常好:

This method works amazing for detecting the new iOS 13 swipe dismissal on the new card modals:

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:

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

@IBAction func btnDismissTap(_ sender: Any) {
    self.dismiss(animated: true, completion: nil)
}

这是一个错误,还是有一种方法可以通过编程方式调用任何滑动"解雇,这样我就可以以相同的方式检测到所有解雇?目前,我正在为我的模式编写额外的解雇"委托方法,以解决此问题,这似乎是不必要的.

Is this a bug or is there a way I can programmatically call whatever the "swipe" dismiss is so I can detect all dismissals the same way? Currently I'm writing extra "dismiss" delegate methods into my modals as a work around and it seems unnecessary.

推荐答案

但是,如果模态通过动作以编程方式自行退出,则不会调用presentationControllerDidDismiss

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

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

不需要调用它,因为您已在代码中自行关闭了模式.您可能不知道该模态已被解雇.您不需要收到解雇信号,因为您首先发出了解雇信号.

It doesn’t need to be called, because you dismissed the modal yourself, in code. You cannot not know that the modal was dismissed. You don’t need to receive a dismissal signal, because you gave the dismissal signal in the first place.

通常不会收到委托方法调用来报告您自己的代码所执行的操作.委托方法报告用户操作.如果您自己在代码中所做的一切都作为委托方法调用而返回,那就太疯狂了.

You typically don’t get a delegate method call reporting something your own code did. Delegate methods report user actions. It would be crazy if everything you yourself did in code came back as a delegate method call.

这篇关于iOS 13 Modals-以编程方式调用滑动解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆