【问题标题】:ViewController not rotating on iOS6ViewController 在 iOS6 上不旋转
【发布时间】:2012-10-03 17:47:06
【问题描述】:

我的大部分应用程序不支持轮换。在支持的方向上,我只选择了肖像。在应用程序使用的 UIViewController 子类上,我有这个:

-(BOOL)shouldAutorotate {
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations {
    NSLog(@"supported?");
    return UIInterfaceOrientationMaskPortrait;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

    NSLog(@"preferred");
    return UIInterfaceOrientationPortrait;
}

在支持方向的 UIViewController 子类中,我有这个:

-(BOOL)shouldAutorotate {
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations {
    NSLog(@"supported?");
    return UIInterfaceOrientationMaskAll;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

    NSLog(@"preferred");
    return UIInterfaceOrientationPortrait;
}

但是,我的应用程序不会在任何视图上旋转,包括这个。怎样才能让它按我的意愿在这里旋转?

【问题讨论】:

  • 您是否将所有方向添加到 Info.plist 中支持的方向?
  • 不,我只选择了肖像作为支持的方向。如果我启用横向,它只会在每个视图控制器上旋转到横向。
  • 你有导航控制器吗?
  • 你应该支持你的应用程序使用的所有方向。所以问题应该是为什么你的视图控制器旋转到横向。
  • @rooster117 是的。 DrummerB - 好的,所以如果它设置为打开,我如何阻止它在某些视图上旋转到横向?

标签: iphone objective-c ios xcode rotation


【解决方案1】:

如果您使用的是导航控制器,请确保在您的 App Delegate 中执行此操作:

self.window.rootViewController = self.navigationController;

有关其他参考资料,请从 SO 中查看此问题:

Rotation behaving differently on iOS6

【讨论】:

  • 这应该可以解决您的问题。前几天我花了几个小时试图解决这个问题,很高兴最终我能够在我的应用程序委托上用这条线解决它。
猜你喜欢
  • 2012-09-14
  • 2012-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多