【问题标题】:Launching app in landscape distorts entire app, when disabling landscape orientation in certain controllers在某些控制器中禁用横向时,横向启动应用程序会扭曲整个应用程序
【发布时间】:2014-11-20 22:19:15
【问题描述】:

我正在我的应用中使用导航控制器。我希望我的所有 viewController 都是纵向的,除了一个支持横向的。

为了在 Stack Overflow 中得到一个接受的答案,我将我的导航控制器子类化并包含以下代码:

iOS 6 - Navigation Controller Landscape Rotations For Some Views While Others Portrait Only

- (BOOL)shouldAutorotate {
    id currentViewController = self.topViewController;

    if ([currentViewController isKindOfClass:[IssueViewController class]])
    return YES;

    return NO;
  }

-(NSUInteger)supportedInterfaceOrientations {
   return UIInterfaceOrientationMaskAll; 
 }

这会挑出我想要旋转的一个视图控制器。一切都很好,除非我在横向启动应用程序。图像被压碎并偏离中心。

此处的屏幕截图:http://imgur.com/a/jyrJ2

对纠正这个有什么建议吗?谢谢!

【问题讨论】:

    标签: ios objective-c iphone swift screen-orientation


    【解决方案1】:

    测试了您的代码。这仅在您更改方向时才能正常工作,但如果您以横向启动应用程序或以横向方式从一个控制器转到另一个控制器,它不会反映当前界面方向的更改。

    使用以下方法,我前段时间用来解决同类问题。

    在 UINavigationController 子类中添加这段代码

    -(BOOL)shouldAutorotate
    {
      return [[self.viewControllers lastObject] shouldAutorotate];
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
      return [[self.viewControllers lastObject] supportedInterfaceOrientations];
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
      return UIInterfaceOrientationPortrait;
    }
    

    在你的 ViewController 中,添加这段代码

    - (BOOL)shouldAutorotate
    {
      return YES;
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
      //Control UIInterfaceOrientationMask here to tell which interface orientations you want to support for this ViewController
      return UIInterfaceOrientationMaskPortrait;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-18
      • 2012-03-06
      相关资源
      最近更新 更多