如何在使用自适应segue时获得对UIPopoverController的引用? [英] How to get reference to UIPopoverController when using adaptive segue?

查看:77
本文介绍了如何在使用自适应segue时获得对UIPopoverController的引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iOS 7应用程序中,我通过此检查检测到segue是否为popover prepareForSegue

In my iOS 7 app, I detected if a segue was a popover via this check in prepareForSegue:

if ([segue isKindOfClass:[UIStoryboardPopoverSegue class]])

但是现在我正在使用自适应segues,在上面的检查中,Present作为Popover segue不再返回true。这是因为segue不再是 UIStoryboardPopoverSegue ,而是 UIStoryboardPopoverPresentationSegue 。但是,人们不能简单地添加 Presentation 字,因为它没有定义。

But now that I am using adaptive segues, the Present as Popover segue is no longer returning true in the above check. This is because segue is no longer a UIStoryboardPopoverSegue, instead it is a UIStoryboardPopoverPresentationSegue. However, one cannot simply add the Presentation word because that's not defined.

适当的方法是什么检测segue是来自自适应segue的弹出窗口,而不是全屏模式演示?

What is the appropriate way to detect when the segue is a popover from an adaptive segue, as opposed to a full screen modal presentation?

并且,你怎么得到对iOS 8 popover的引用?以下是我正在为iOS 7做的事情,但又因为它不是 UIStoryboardPopoverSegue 这会导致崩溃。

And, how do you get a reference to the popover for iOS 8? The following is what I'm doing for iOS 7 but again because it's not a UIStoryboardPopoverSegue this will cause a crash.

UIPopoverController *popover = ((UIStoryboardPopoverSegue *)segue).popoverController;
popover.popoverContentSize = CGSizeMake(380, 1000);


推荐答案

实际上没有必要获得对适用于iOS 8的popover。您可以直接在显示的视图控制器中访问 popoverPresentationController 。然后使用 dismissViewControllerAnimated 来关闭视图控制器。您可以直接在通过 preferredContentSize 显示的视图控制器中设置弹出窗口内容大小。我发现我不需要在 prepareForSegue 中获取引用,至少在iOS 8上运行时.iOS 7是另一回事。

There actually was no need to get a reference to the popover for iOS 8. You can access the popoverPresentationController directly in the view controller that's presented. Then use dismissViewControllerAnimated to dismiss the view controller. You can set the popover content size directly in the view controller that's being presented via preferredContentSize. I found I had no need to obtain a reference in prepareForSegue, at least when running on iOS 8. iOS 7 is a different story.

这篇关于如何在使用自适应segue时获得对UIPopoverController的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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