UIPopoverController w/ UINavigationController 子视图 contentSizeForViewInPopover 不适用于父视图

发布于 2024-09-03 06:33:01 字数 403 浏览 4 评论 0原文

我有一个带有子类 UINavigationController 的 UIPopoverController 。父视图和子视图都是 UITableview。

当我最初使用 contentSizeForViewInPopover = (320,480) 调用父视图时,效果很好。

当我单击子视图时,我将弹出窗口的大小调整为 contentSizeForViewInPopover = (320,780)

当返回到父视图时,我无法将弹出窗口的大小调整回 contentSizeForViewInPopover = (320,480)。弹出窗口保持在 (320,780) 大小。

一直在尝试一切,但只是错过了一些东西。有人知道在上述场景中如何使用 UIPopoverControllers 调整视图大小吗?

提前致谢!!

I have a UIPopoverController with a subclass UINavigationController. Both the parent and child views are UITableviews.

When i call parent view originally with contentSizeForViewInPopover = (320,480) it works great.

When i click into the child view i resize the popover to contentSizeForViewInPopover = (320,780)

When return back to the parent view i cannot get the popover to resize back to contentSizeForViewInPopover = (320,480). the popover stays at the (320,780) size.

Been trying everything but just missing something. Anyone know how resize the view with UIPopoverControllers in the above scenario?

Thanks in Advance!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

不顾 2024-09-10 06:33:01

视图控制器的 contentSizeForViewInPopover 属性仅设置其包含的 UIPopoverController 的默认(初始)大小。要在任意时间调整 UIPopoverController 的大小,您必须设置其 popoverContentSize 属性。请注意,popoverContentSizeUIPopoverController 的属性,而不是视图控制器的属性(因此您可能需要对 popover 控制器的引用) )。

要在每次视图控制器成为 UINavigationController 的顶部视图控制器时重置弹出窗口的大小,您可以使用 UINavigationControllerDelegate 协议方法:

navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (viewController == viewControllerToResize) {
        referenceToUIPopoverController.popoverContentSize = CGSizeMake(320,480);
    }
}

The contentSizeForViewInPopover property of the view controller only sets the default (initial) size of its containing UIPopoverController. To resize the UIPopoverController at an arbitrary time, you must set its popoverContentSize property. Note that popoverContentSize is a property of the UIPopoverController and not of the view controller (so you'll probably need a reference to the popover controller around).

To reset the popover's size every time a view controller becomes the top view controller of a UINavigationController, you can use the UINavigationControllerDelegate protocol methods:

navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (viewController == viewControllerToResize) {
        referenceToUIPopoverController.popoverContentSize = CGSizeMake(320,480);
    }
}
甜嗑 2024-09-10 06:33:01

我遇到了同样的问题,但上述解决方案都不适合我。然而,在尝试结合他们的方法时,我受到启发尝试一种稍微不同的方法来解决这个问题。这对我有用:

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    viewController.contentSizeForViewInPopover = navigationController.topViewController.view.frame.size;
}

我有三个不同的弹出窗口,每个弹出窗口都使用导航视图控制器。该解决方案具有适用于所有这些解决方案的良好副作用,因为它没有对任何弹出窗口控制器进行特定引用,但最终使用当前正在使用的弹出窗口控制器中的 popoverContentSize 。

I had the same problem, but none of the above solutions worked for me. However, in trying to combine their approaches, I was inspired to try a slightly different way to attack the problem. This works for me:

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    viewController.contentSizeForViewInPopover = navigationController.topViewController.view.frame.size;
}

I have three different popovers that each use navigation view controllers. This solution has the nice side effect of working for all of them because it doesn't make a specific reference to any of the popover controllers, but ends up using the popoverContentSize from the popover controller currently being used.

相权↑美人 2024-09-10 06:33:01

在我的项目中,我必须动态更改弹出窗口的大小。

我制作了弹出窗口内容控制器的原始控制器委托,并实现了每次大小更改时调用的委托方法:

代码如下,希望对某人有所帮助:

-(void) popover:(UIViewController*)controller didChangeSize:(CGSize)size{

    if ([controller class] == [AZViewController class]){
        if (!_popoverController){
            _popoverController = [[UIPopoverController alloc] initWithContentViewController:controller]; 
        }

        _popoverController.popoverContentSize = size;
    }
}

In my project I had to dynamically change the size of the popover.

I made the original controller delegate of my popover content controller, and implemented it's delegate method that is called each time the size is changed:

The code is bellow, hope it helps somebody:

-(void) popover:(UIViewController*)controller didChangeSize:(CGSize)size{

    if ([controller class] == [AZViewController class]){
        if (!_popoverController){
            _popoverController = [[UIPopoverController alloc] initWithContentViewController:controller]; 
        }

        _popoverController.popoverContentSize = size;
    }
}
好听的两个字的网名 2024-09-10 06:33:01

我想我也遇到了同样的问题,我通过每次视图即将出现时在弹出窗口中设置视图的大小来解决它。就像这样:

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    self.contentSizeForViewInPopover = CGSizeMake(320, 444); //Set your own size
}

我希望这对你有帮助。

I think I had the same problem and I solved it by setting the size for the view in the popover every time the view was about to appear. Like this:

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    self.contentSizeForViewInPopover = CGSizeMake(320, 444); //Set your own size
}

I hope this helps you.

以歌曲疗慰 2024-09-10 06:33:01

我想我可能已经弄清楚了这一点,因为我在这个问题上挣扎了一段时间。可能有点乐观,所以如果此解决方案不适合您,请随时发表评论。

在显示导航层次结构的每个 viewController 中,将 viewDidAppear: 方法中的 contentSizeForViewInPopover 属性设置为其适当的大小。

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self setContentSizeForViewInPopover:CGSizeMake(320, 320)];
}

我发现的另一件事是,在编辑文本字段时点击返回时,尺寸保持较小,而不是较大的先前视图。在控制器的 viewWillDisappear 中的 textField 上调用 resignFirstResponder 方法。

我很好奇这个解决方案是否跨 SDK 有效。

I think I might have figured this out as I struggled with this issue for a while now. Might be a bit optimistic so please feel free to comment if this solution isn't working for you.

In each viewController displayed with the navigation hierarchy, set the contentSizeForViewInPopover property in the viewDidAppear: method to its appropriate size.

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self setContentSizeForViewInPopover:CGSizeMake(320, 320)];
}

Another thing I picked up is that when tapping back while editing a textField, the size stays small instead of the larger previous view. Call the resignFirstResponder method on your textField in the controller's viewWillDisappear.

I'm curious whether this solution works across sdks.

方圜几里 2024-09-10 06:33:01

在尝试了很多事情之后,@chuck-k 的答案帮助我很好地解决了 iOS7 中的 UINavigationController 弹出窗口问题。

这就是我所做的:

  • 对于 UINavigationController 中的每个 UIViewController,我计算想要在方法 - (CGSize)contentSizeForViewInPopover 中显示的内容大小加上 navigationController.navigationBar.frame.size.height< /code> (我认为总是 44)。我在这些 UIViewController 中没有使用任何其他弹出窗口功能。

  • 我声明了将 UINavigationController 创建为 UINavigationControllerDelegate 的 UIViewController

  • 然后在委托中......

.....

- (void)navigationController:(UINavigationController *)navigationController willShowViewController: (UIViewController *)viewController animated:(BOOL)animated {

    BOOL popoverAnimation = NO;

    if ( self.myPopoverController.popoverContentSize.height < viewController.contentSizeForViewInPopover.height ) popoverAnimation = YES;

    [self.myPopoverController setPopoverContentSize:viewController.contentSizeForViewInPopover animated:popoverAnimation];
}

高度检查将当前视图控制器的弹出框内容大小与“传入”视图控制器弹出框内容大小进行比较。当从更大的 --> 开始时,我使用动画 = NO较小的弹出框内容大小,否则我会在 iOS7 中看到一些不稳定的重新定位动画。但特别的是,如果动画 = NO 当从较小的 --> 开始时较大弹出窗口内容大小,弹出窗口大小将增加到我预期的大小不会显示比之前更大的内容较小的内容大小...设置 animation = YES 为我解决了这个问题。 (我只检查高度,因为在我的情况下,宽度是固定的。)

通过使用这种技术,几乎一切最终都让我满意,我希望这可以帮助其他人。

After trying many things, the answer by @chuck-k helped me decently resolve for my UINavigationController popover woes in iOS7.

Here's what I did:

  • for each UIViewController within the UINavigationController I calculate the content size I want displayed in method - (CGSize)contentSizeForViewInPopover plus navigationController.navigationBar.frame.size.height (which is always 44 I think). I don't use any other popover functionality in these UIViewControllers.

  • I declared my UIViewController that creates the UINavigationController as a UINavigationControllerDelegate

  • Then in the delegate....

.....

- (void)navigationController:(UINavigationController *)navigationController willShowViewController: (UIViewController *)viewController animated:(BOOL)animated {

    BOOL popoverAnimation = NO;

    if ( self.myPopoverController.popoverContentSize.height < viewController.contentSizeForViewInPopover.height ) popoverAnimation = YES;

    [self.myPopoverController setPopoverContentSize:viewController.contentSizeForViewInPopover animated:popoverAnimation];
}

The height check compares the current view controller's popover content size to the "incoming" view controller popover content size. I use animation = NO when going from a larger --> smaller popover content size, because otherwise I get some jerky repositioning animation in iOS7. But peculiarly if animation = NO when going from a smaller --> larger popover content size, the popover size would increase to the size I was expecting but would not display content larger than the previously smaller content size... setting animation = YES resolved this issue for me. (I only check height because in my case the width is fixed.)

By using this technique almost everything finally works to my satisfaction and I hope this might help someone else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文