【发布时间】:2013-12-23 21:43:24
【问题描述】:
我有一个旧应用程序,它仍然存在于 iTunes 上,用 iOS 5 编写。我想更新它以在 ios 6 和 7 上运行。到目前为止一切都很好,我已经更新了我的代码以使用 ARC .然而,当我试图保持同样的自转理念时,我总是碰壁。我已经检查了 SO 中的相关主题,例如:
Forcing landscape and autorotate in iOS 7,
Autorotate in iOS 6 has strange behaviour
并遵循一个类似的主题,我发现了这个:
iOS 6 Autorotation Problems and Help
这导致我做了以下事情:
我已经在我的 AppDelegate 中设置了 rootViewController,如下所示:
self.preloadingViewController = [[PreloadingViewController alloc] initWithNibName:@"PreloadingViewController" bundle:nil];
self.window.rootViewController = self.preloadingViewController;
我已放置:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
在我的 AppDelegate 中。我已经在我的所有应用的 UIViewController(包括上面提到的 PreloadingViewController)的 SuperViewController(继承术语中的父级)中覆盖了 shouldAutorotate 和 supportedInterfaceOrientations:
- (BOOL)shouldAutorotate{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
在每个子 UIViewController 中,我重写了
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
使用代码以适合纵向和横向方向的方式布局 ui 元素。
最后是我应用的plist文件在
下支持的界面方向
包含:
纵向(底部主页按钮)、横向(左侧主页按钮)、横向 (右主页按钮)
我想要支持的所有方向。
尽管如此,即使在我的 rootViewController 上的每个方向更改都会调用 supportedInterfaceOrientations 和 shouldAutorotate,但永远不会调用 willAnimateRotationToInterfaceOrientation。我什至在我的 SuperViewController 中覆盖了 shouldAutomaticallyForwardRotationMethods 以返回 YES,但无济于事。
我在这里做错了什么?有任何想法吗?我什至认为旧的 ios5 - 风格的 xib 会导致问题,但我认为情况并非如此。
提前致谢。
【问题讨论】:
-
你的viewcontroller可见吗?
-
willAnimateRotationToInterfaceOrientation: 不再为不可见的视图控制器调用方法。因此,如果您的视图控制器呈现另一个接管,则只有另一个会听到这些通知。
-
rootViewController 不可见。尽管我注意到只有 rootViewController 会收到有关方向更改的通知,但它的
willAnimateRotationToInterfaceOrientation永远不会被调用。
标签: ios iphone objective-c uiviewcontroller autorotate