ios - 在某些 Controller 中禁用横向时,横向启动应用程序会扭曲整个应用程序

标签 ios objective-c iphone swift screen-orientation

我在我的应用程序中使用导航 Controller 。我希望我的所有 viewController 都是纵向的,除了一个支持横向。

根据 Stack Overflow 中接受的答案,我将我的导航 Controller 子类化并包含以下代码:

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; 
 }

这会挑出我想要旋转的一个 View Controller 。一切都很好,除了当我横向启动应用程序时。图像被压碎并偏离中心。

屏幕截图在这里:http://imgur.com/a/jyrJ2

关于纠正这个问题有什么建议吗?谢谢!

最佳答案

测试了你的代码。这仅在您更改方向时工作正常,但如果您横向启动应用程序或横向从一个 Controller 切换到另一个 Controller ,它不会根据当前界面方向反射(reflect)更改。

使用以下方法,我之前曾用它来解决过同类问题。

在 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;
}

关于ios - 在某些 Controller 中禁用横向时,横向启动应用程序会扭曲整个应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27050700/

相关文章:

ios - AppStore ios版本需要ipad媒体

objective-c - Sprite Kit 相当于 clipsToBounds :

iphone - 拥有一个包含许多子层的 CALayer。当在子图层上调用 setNeedsDisplay 时,我收到无效上下文错误

ios - 无法在重构的 Storyboard上设置标签栏角标(Badge)值

iphone - 在我的 iPhone 应用程序中评价我在 iTunes 中的应用程序

ios - 在 mkMapview 中显示注释的不同图像

ios - Azure 通知,注册设备服务器端。适用于 FCM 但不适用于 APNS 的通知

objective-c - 获取用于更改空间的 key

ios - 使用 CGPDF 的简单 Pdf 查看器

ios - AudioKit示例MicrophoneAnalysis的最大频率