带有嵌入式导航控制器的Popover不支持背面导航的尺寸 [英] Popover with embedded navigation controller doesn't respect size on back nav

查看:80
本文介绍了带有嵌入式导航控制器的Popover不支持背面导航的尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个托管UINavigationController的UIPopoverController,它包含一小部分视图控制器。

I have a UIPopoverController hosting a UINavigationController, which contains a small hierarchy of view controllers.

我按照文档操作,对于每个视图控制器,我设置视图的弹出窗口 - 上下文大小如下:

I followed the docs and for each view controller, I set the view's popover-context size like so:

[self setContentSizeForViewInPopover:CGSizeMake(320, 500)];

(每个控制器的大小不同)

(size different for each controller)

当我在层次结构中向前导航时,这可以正常工作 - 弹出窗口自动动画大小更改以对应于推送的控制器。

This works as expected as I navigate forward in the hierarchy-- the popover automatically animates size changes to correspond to the pushed controller.

但是,当我通过导航栏的后退按钮浏览视图堆栈中的后退时,弹出窗口不会改变大小 - 它仍然保持与最深的一样大到达了。这似乎打破了我;我希望popover能够尊重在视图堆栈中弹出时设置的大小。

However, when I navigate "Back" through the view stack via the navigation bar's Back button, the popover doesn't change size-- it remains as large as the deepest view reached. This seems broken to me; I'd expect the popover to respect the sizes that are set up as it pops through the view stack.

我错过了什么?

谢谢。

推荐答案

好的,我正在努力解决同样的问题。以上解决方案都不适合我,这就是为什么我决定做一些调查并找出它是如何工作的原因。
这是我发现的:
- 当你在视图控制器中设置 contentSizeForViewInPopover 时,它不会被popover本身改变 - 即使导航到不同的控制器时弹出窗口大小可能会改变。
- 当导航到不同的控制器时弹出窗口的大小会改变,同时返回时,弹出窗口的大小不会恢复
- 在viewWillAppear中改变弹出窗口的大小会产生非常奇怪的动画(当我们使用时)比如你在popover里面的popController) - 我不推荐它
- 对我来说,设置控制器内的硬编码大小根本不起作用 - 我的控制器有时候很大,有时很小 - 控制器会呈现它们有关于大小的想法

Ok, I was struggling with the same issue. None of the above solutions worked for me pretty nicely, that is why I decided to do a little investigation and find out how this works. This is what I discovered: - When you set the contentSizeForViewInPopover in your view controller it won't be changed by the popover itself - even though popover size may change while navigating to different controller. - When the size of the popover will change while navigating to different controller, while going back, the size of the popover does not restore - Changing size of the popover in viewWillAppear gives very strange animation (when let's say you popController inside the popover) - I'd not recommend it - For me setting the hardcoded size inside the controller would not work at all - my controllers have to be sometimes big sometimes small - controller that will present them have the idea about the size though

所有痛苦的解决方案如下:
你必须重置 currentSetSizeForPopover的大小在viewDidAppear中。但是你必须要小心,当你设置的字段大小与字段 currentSetSizeForPopover 中设置的相同时,弹出框不会改变大小。为此,您可以首先设置假大小(将与之前设置的大小不同),然后设置适当的大小。即使您的控制器嵌套在导航控制器内,此解决方案也会起作用,当您在控制器之间导航时,popover会相应地更改其大小。

A solution for all that pain is as follows: You have to reset the size of currentSetSizeForPopover in viewDidAppear. But you have to be careful, when you will set the same size as was already set in field currentSetSizeForPopover then the popover will not change the size. For this to happen, you can firstly set the fake size (which will be different than one which was set before) followed by setting the proper size. This solution will work even if your controller is nested inside the navigation controller and popover will change its size accordingly when you will navigate back between the controllers.

您可以轻松创建类别在UIViewController上使用以下帮助器方法来设置大小:

You could easily create category on UIViewController with the following helper method that would do the trick with setting the size:


- (void) forcePopoverSize {
    CGSize currentSetSizeForPopover = self.contentSizeForViewInPopover;
    CGSize fakeMomentarySize = CGSizeMake(currentSetSizeForPopover.width - 1.0f, currentSetSizeForPopover.height - 1.0f);
    self.contentSizeForViewInPopover = fakeMomentarySize;
    self.contentSizeForViewInPopover = currentSetSizeForPopover;
}

然后只需在 -viewDidAppear 所需的控制器。

Then just invoke it in -viewDidAppear of desired controller.

这篇关于带有嵌入式导航控制器的Popover不支持背面导航的尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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