如何在iOS 9中检测弹出窗口何时被解除 [英] How to detect when a popover is dismissed in iOS 9

查看:103
本文介绍了如何在iOS 9中检测弹出窗口何时被解除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更新应用以使用通用故事板。我已经使用界面构建器创建了一个popover segue到一个新的viewcontroller,方法是从一个按钮拖动到我的新viewcontroller并选择'Present As Popover'作为segue的类型。

I'm updating an app to use universal storyboards. I've created a popover segue to a new viewcontroller using interface builder by dragging from a button to my new viewcontroller and selecting 'Present As Popover' as the kind of segue.

当用户按下弹出窗口(解除它)时,我需要在呈现视图控制器中得到通知,以便我可以撤消他们的操作。我该怎么做?

When the user presses outside of the popover (dismissing it) I need to be notified in the presenting view controller so I can undo their actions. How can I do this?

通常我会手动创建popover并使我的viewcontroller成为popover的委托;允许我使用popoverControllerDidDismissPopover委托回调。但是,这在iOS9中已被弃用,即使不是我也不知道在哪里找到popover所以我可以将其委托设置为我的视图控制器。

Normally I would have created the popover manually and made my viewcontroller the popover's delegate; allowing me to use the popoverControllerDidDismissPopover delegate call back. However, this is deprecated in iOS9 and even if it wasn't I've no idea where to find the popover so I can set its delegate to my view controller.

推荐答案

不确定您所指的哪种方法已被弃用,但您仍然可以使用 UIPopoverPresentationControllerDelegate 来实现此目的。类似于:

Not sure which method you're referring to as being deprecated but you can still use the UIPopoverPresentationControllerDelegate to achieve this. Something like:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "popoverSegue" {
        let vc = segue.destinationViewController
        sortVC.modalPresentationStyle = .Popover
        sortVC.popoverPresentationController?.sourceRect = filterButton.bounds
        sortVC.preferredContentSize = CGSizeMake(216, 150)
        sortVC.popoverPresentationController!.delegate = self
    }
}

然后使用

func popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController)

处理解雇的方法。

这篇关于如何在iOS 9中检测弹出窗口何时被解除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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