Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
529 views
in Technique[技术] by (71.8m points)

ios - 如何检测iOS 9中何时关闭弹出窗口(How to detect when a popover is dismissed in iOS 9)

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.

(我已经使用界面构建器通过将新按钮从按钮拖到我的新的ViewController中并选择“ Present As Popover”作为弹出按钮,为新的ViewController创建了一个弹出按钮。)

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?

(我怎样才能做到这一点?)

Normally I would have created the popover manually and made my viewcontroller the popover's delegate;

(通常,我会手动创建弹出窗口,并使ViewController成为弹出窗口的委托。)

allowing me to use the popoverControllerDidDismissPopover delegate call back.

(让我可以使用popoverControllerDidDismissPopover委托回调。)

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.

(但是,iOS9中不推荐使用此方法,即使不是,我也不知道在哪里可以找到弹出窗口,因此可以将其委托设置为我的视图控制器。)

  ask by Mark Bridges translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

(不知道您指的是哪个方法已被弃用,但是您仍然可以使用UIPopoverPresentationControllerDelegate来实现。)

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
    }
}

And then use the

(然后使用)

func popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController)

method to handle its dismissal.

(处理其解雇的方法。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...