iPhone - 替代横向视图问题

发布于 2024-10-17 03:14:52 字数 595 浏览 6 评论 0原文

我遇到了横向模式问题,但找不到解决办法。基本上,我有一个选项卡栏应用程序,在第一个选项卡中我有导航控制器。在此导航控制器中,第一个视图包含带有项目的表格,单击该项目后,将推送描述该项目的详细视图。

我需要为列表视图和详细视图实现横向模式,但对于列表视图,我需要为横向模式使用不同的视图控制器(通常,类似于封面流)。详细视图只是改变方向,在这种情况下不需要使用备用视图控制器。

根据 Apple 的替代视图示例,我尝试通过为列表视图控制器实现模式视图控制器来实现此行为。当我处于列表视图时(当我将设备转为横向模式时,覆盖流视图控制器会正确呈现),这工作得很好。当我显示详细视图时,问题就出现了。当我更改设备方向时,封面流再次出现。我期望的是,仅当列表视图出现在屏幕上时才会显示封面流程。看起来模态视图控制器总是可见的,无论 NC 堆栈上当前有什么 VC。

在我看来,将模态 VC 呈现为特定 VC 的横向视图不适用于多个导航级别。

我还尝试将横向视图作为子视图添加到视图控制器视图中。使用此解决方案时,我的导航级别没有问题,但这里的问题是选项卡栏在横向模式下没有隐藏。我需要隐藏封面流的选项卡栏,这是通过呈现模态 VC 来实现的。

对于这个问题的任何帮助,我将不胜感激。

非常感谢!

I'm having the landscape mode issue and I can not find the way out. Basically, I'm having a tab bar application and in the first tab i have navigation controller. In this navigation controller, first view contains table with items and after clicking the item, detail view describing the item is pushed.

I need to implement landscape mode for both list and detail view, but for list view, i need to use different view controller for landscape mode (generally, something like cover flow). Detail view is just changing orientation and no need to use alternate view controller in this case.

I tried to achieve this behaviour by implementing modal view controller for list view controller, according to Alternate Views example by Apple. This works fine when I'm in list view (when I turn device into landscape mode, cover flow view controller is correctly presented). Problem comes when I'm showing detail view. When I change the device orientation, cover flow shows up again. What I expected is that cover flow will be presented only in case that list view is on the screen. It seems like modal view controller is always visible no matter what VC is currently on the stack of NC.

It seems to me that presenting modal VC as landscape view for particular VC is not working for multiple navigation levels.

I also tried to add landscape view as a subview into view controllers view. When using this solution, i have no problem with navigation levels, but issue here is that tab bar is not hidden in landscape mode. I need to hide tab bar for cover flow, which is achieved by presenting modal VC.

I will appreciate any help with this issue.

Great thanks!

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

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

发布评论

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

评论(1

音盲 2024-10-24 03:14:52

在详细视图控制器中,您可以使用类似这样的东西完全设置不同的视图(来自我最近的项目的代码):

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation 
                                duration:(NSTimeInterval)duration
{
    if ([graphView superview]) {
        if (toOrientation == UIInterfaceOrientationPortrait ||
            toOrientation == UIInterfaceOrientationPortraitUpsideDown) {
            [graphView removeFromSuperview];
        }
    } else {
        if (toOrientation == UIInterfaceOrientationLandscapeLeft ||
            toOrientation == UIInterfaceOrientationLandscapeRight) {
            [[self view] endEditing:YES];
            [[self view] addSubview:graphView];
        }       
    }
}

现在,当您处于横向状态时隐藏选项卡栏(有点黑客,但有效):

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    UIInterfaceOrientation toOrientation = self.interfaceOrientation;

    if ( self.tabBarController.view.subviews.count >= 2 )
    {
        UIView *transView = [self.tabBarController.view.subviews objectAtIndex:0];
        UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1];

        if(toOrientation == UIInterfaceOrientationLandscapeLeft ||
           toOrientation == UIInterfaceOrientationLandscapeRight) {                                     
            transView.frame = CGRectMake(0, 0, 480, 320 );
            tabBar.hidden = TRUE;
        }
        else
        {                               
            transView.frame = CGRectMake(0, 0, 320, 480);         
            tabBar.hidden = FALSE;
        }
    }
}

对于在这个项目中,我添加了一个名为“graphView”的视图,当且仅当在横向模式下时我想显示该视图,然后我想隐藏选项卡栏。我认为这听起来与您所追求的相似。

我预见的唯一潜在问题是,如果您在推送详细视图之前进入横向模式,事情可能会变得不稳定。因此,您可能想在列表视图控制器中使用这些方法。这个特殊的问题对我来说从来没有出现过,但在我意识到它没有实际意义之前,我就考虑过这个问题。

In the detail view controller, you could set up a different view entirely using something like this (code from a recent project of mine):

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation 
                                duration:(NSTimeInterval)duration
{
    if ([graphView superview]) {
        if (toOrientation == UIInterfaceOrientationPortrait ||
            toOrientation == UIInterfaceOrientationPortraitUpsideDown) {
            [graphView removeFromSuperview];
        }
    } else {
        if (toOrientation == UIInterfaceOrientationLandscapeLeft ||
            toOrientation == UIInterfaceOrientationLandscapeRight) {
            [[self view] endEditing:YES];
            [[self view] addSubview:graphView];
        }       
    }
}

And now to hide the tabbar when you are in landscape (bit of a hack, but works):

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    UIInterfaceOrientation toOrientation = self.interfaceOrientation;

    if ( self.tabBarController.view.subviews.count >= 2 )
    {
        UIView *transView = [self.tabBarController.view.subviews objectAtIndex:0];
        UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1];

        if(toOrientation == UIInterfaceOrientationLandscapeLeft ||
           toOrientation == UIInterfaceOrientationLandscapeRight) {                                     
            transView.frame = CGRectMake(0, 0, 480, 320 );
            tabBar.hidden = TRUE;
        }
        else
        {                               
            transView.frame = CGRectMake(0, 0, 320, 480);         
            tabBar.hidden = FALSE;
        }
    }
}

For this project, I added a view called "graphView" that I wanted to appear if and only if in landscape mode, and then I wanted to tabbar to be hidden. This sounds similar to what you're after, I think.

The only potential problem I foresee is that if you enter landscape mode before the detail view is pushed, things could get wonky. Therefore you may want to use these methods in the list view controller instead. This particular problem never arose for me, but it's something I thought about before I realized it was moot.

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