UISplitViewController非root,强制自定义旋转方法,使主视图消失

发布于 2024-10-08 22:55:04 字数 934 浏览 0 评论 0原文

我正在尝试在选项卡栏内添加拆分视图,并且由于拆分视图不是根,因此它无法正确获取旋转通知,因此永远不会调用委托的方法来将按钮添加到工具栏在详细视图中。

我已经对它进行了装配,这样我就可以在旋转时生成弹出窗口,但是当调用此方法时,视图将从横向模式中消失,如果您激活它然后旋转回横向模式,它是一个黑色的空盒子,其中主视图曾经是。我该如何摆脱这种情况的发生?

-(void) displayPopover:(id)sender
{
    //Toggle the popover: if it's showing, hide it
    if (popoverController != nil && [popoverController isPopoverVisible]) 
    {
        [popoverController dismissPopoverAnimated:NO];
    }
    else
    {
        //Create a Popover displaying the master view
        if (popoverController == nil)
        {
            popoverController=[[UIPopoverController alloc] initWithContentViewController:self->rootController];
            popoverController.popoverContentSize=CGSizeMake(300, 500);
    }
    [popoverController presentPopoverFromBarButtonItem:[detailController.toolbar.items objectAtIndex:0] permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
}

I'm trying to add a split view inside of a tab bar, and since the split view isn't the root, it doesn't properly get the rotation notifications, so the delegate's methods are never called to add the button to the toolbar in the detail view.

I've rigged it up so I can generate the popover when rotated, but when this method is called, the view dissappears from the landscape mode, and if you activate it and then rotate back into landscape, it's a black empty box where the master view used to be. How do I get rid of this occuring?

-(void) displayPopover:(id)sender
{
    //Toggle the popover: if it's showing, hide it
    if (popoverController != nil && [popoverController isPopoverVisible]) 
    {
        [popoverController dismissPopoverAnimated:NO];
    }
    else
    {
        //Create a Popover displaying the master view
        if (popoverController == nil)
        {
            popoverController=[[UIPopoverController alloc] initWithContentViewController:self->rootController];
            popoverController.popoverContentSize=CGSizeMake(300, 500);
    }
    [popoverController presentPopoverFromBarButtonItem:[detailController.toolbar.items objectAtIndex:0] permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
}

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

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

发布评论

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

评论(3

蔚蓝源自深海 2024-10-15 22:55:04

您需要使用以下方法从窗口中删除所有对象:

 [appdelegate window ] subviews] objectAtIndex:0] removeFromSuperview]; 

然后将您的 splitview 添加到窗口,您可以获得视图回调。

You will need to remove all the objects from window using:

 [appdelegate window ] subviews] objectAtIndex:0] removeFromSuperview]; 

Then add your splitview to the window, you can get the view callbacks.

枕头说它不想醒 2024-10-15 22:55:04

我建议要么找到一种方法让 SplitViewController 成为 root,要么创建允许非 root 放置的 UISplitViewController 的自定义子类。
我真的很喜欢 Matt Gemmell 在这里所做的: http://mattgemmell.com/2010/ 07/31/mgsplitviewcontroller-for-ipad
使用像 Matt 那样的自定义子类将使您受益于 SplitView 作为根所允许的所有相同委托方法。我在一个项目中使用了它,我希望我的 SplitView 显示为模式 - 使用传统的 UISplitViewController 几乎不可能。

I would recommend either finding a way to get your SplitViewController to be root, or creating a custom subclass of the UISplitViewController that allows for non-root placement.
I really like what Matt Gemmell did here: http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad
Using a custom subclass like Matt's will allow you to benefit from all the same delegate methods that a SplitView as root would allow. I used it in a project where I wanted my SplitView to appear as a modal - almost impossible with a traditional UISplitViewController.

烟雨凡馨 2024-10-15 22:55:04

所以你的分割视图启用了旋转(shouldAutorotateToInterfaceOrientation:),现在你必须确保选项卡控制器也启用了旋转(应该是appDelegate,对吗?)并且你必须确保TabBar 中的所有其他视图也启用了旋转!

因此,如果您的 TabBar 包含 2 个选项卡,您必须将旋转设置为 3 个类别。

so your split view has rotation enabled (shouldAutorotateToInterfaceOrientation:) now you have to make sure that the tab controller has also rotation enabled (should be the appDelegate, am I right?) AND you have to make sure that every other view that is in your TabBar has also rotation enabled!

so if your TabBar contains 2 tabs you have to set the rotation in 3 classes.

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