【问题标题】:Navigation Based App : only one landscape UIVIewController基于导航的应用程序:只有一个景观 UIVIewController
【发布时间】:2013-04-25 11:42:35
【问题描述】:

对 Objective C 和 iOS 来说还是新手,我面临一个新问题。

这很简单,我的应用程序中只需要一个 UIViewController 即可处于横向模式,所以我以这种方式构建了我的应用程序:

一个自定义 UINAvigationController :MyNavController 在我的 MainStoryBoard.storyboard 中设置为“是初始视图控制器”。然后我添加这个 navController...:

- (NSUInteger)supportedInterfaceOrientations
{

    return [[self topViewController] supportedInterfaceOrientations];
}

... 能够控制自定义导航控制器的哪些 UIVIewController 子节点可以处于横向。

在景观 UIVIewController 我设置:

- (NSUInteger)supportedInterfaceOrientations
{
        return UIInterfaceOrientationMaskLandscapeLeft ;
        return UIInterfaceOrientationMaskPortrait; 
}

所以我可以得到这个控制器景观与否。 在我的笔尖(landscape.xib)的这个风景控制器中,我在 UIPortrait 模式下设置了一个欢迎视图,在这个视图后面我有我的风景视图。所以当用户按下控制器时,他看到他必须转动他的 iPhone 屏幕。我使用以下方式聆听方向变化:

[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged)  name:UIDeviceOrientationDidChangeNotification  object:nil];

在orientationChanged中,我隐藏了纵向视图,然后我们可以看到横向视图。

它可以工作,但是当你快速旋转时效果很差,有时视图被隐藏有时不隐藏。所以有我的问题:

  • 在基于导航的应用中,只有一个控制器景观支持的最佳方法是什么?
  • 我用:

    [self.navigationController pushNavigationController:landscapeController];

是否有另一种方法不推动 ladnscapeController 使其不再依赖于 navController ?

谢谢大家,欢迎任何帮助。

【问题讨论】:

    标签: iphone ios objective-c uiviewcontroller orientation


    【解决方案1】:

    在推送下一个控制器之前使用此代码

    [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
    

    pop to back 控制器时使用此代码

     [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationIsPortrait(UIInterfaceOrientationMaskPortrait);
    

    【讨论】:

    • 我在我的应用中使用此代码只有一页是横向模式
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 2015-07-02
    • 1970-01-01
    • 2011-04-14
    相关资源
    最近更新 更多