【问题标题】:ios- view controller doesn't load in current orientationios-view 控制器未按当前方向加载
【发布时间】:2014-10-07 10:44:43
【问题描述】:

我正在使用 UINavigationController 的子类来管理我的应用程序的旋转。

@implementation rotatingNavigationController


- (BOOL)shouldAutorotate
{
    return [self.topViewController shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations
{
    return [self.topViewController supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.topViewController preferredInterfaceOrientationForPresentation];
}

在我的第一个视图中,我只允许纵向:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

我使用情节提要中创建的推送转场推送到新的视图控制器。新的视图控制器支持所有界面方向:

- (BOOL)shouldAutorotate
{

    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAll;
}

新的视图控制器总是以纵向加载,无论设备处于什么方向。如果我在视图加载后将设备物理地切换到纵向模式并返回横向,它会正确旋转。我该如何纠正这个问题,我需要在视图加载时以设备所在的任何方向加载视图?

【问题讨论】:

  • 自 iOS6 以来,我在 UINavigationController 内部的不同方向的视图控制器方面遇到了很多问题,并且没有找到合适的解决方案。我只是尽量避免这种情况并以模态方式呈现横向视图控制器。

标签: ios objective-c


【解决方案1】:

当您推送新控制器时。然后检查状态栏的界面方向:

 -(BOOL)shouldAutorotate
{
   if(isPushingViewVC)
      return NO
   return YES;
}

还有

- (NSUInteger)supportedInterfaceOrientations
{
    if(isPushingViewVC)
    {
        switch ([UIApplication sharedApplication].statusBarOrientation)
        {
            case UIInterfaceOrientationLandscapeLeft:
                return UIInterfaceOrientationMaskLandscapeLeft;
                break;
            case UIInterfaceOrientationPortrait:
                return UIInterfaceOrientationMaskPortrait;
                break;
            case UIInterfaceOrientationPortraitUpsideDown:
                return UIInterfaceOrientationMaskPortraitUpsideDown;
                break;
            default:
                return UIInterfaceOrientationMaskLandscape;
                break;
        }
    }
     return UIInterfaceOrientationMaskAll;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-31
    相关资源
    最近更新 更多