【发布时间】:2011-08-02 07:38:39
【问题描述】:
在我的应用程序中,我使用了一个 UITabbarController,它可以完美地旋转到所有视图控制器中的所有 UIInterfaceOrientations。但是当我之后将 UIView 添加到 UIWindow 时,它不会添加到当前的 UIInterfaceOrientation 中,而是始终添加到 UInterfaceOrientationPortrait 中(这是应用程序的默认设置)。它也不会旋转到新的方向。我使用以下方法添加 ViewController:
LoginViewController *loginViewController = [[LoginViewController alloc] init];
[self.window addSubview:[loginViewController view]];
我有
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
NSLog(@"%@", @"YES IT WILL!");
}
在 LoginViewController.m 中,但永远不会记录任何内容。知道为什么子视图不会旋转吗?
侧滑
编辑: 找到了解决方案: 显然 UIWindow 应该只有一个子视图,而不是更多,否则事情会一团糟,所以我打电话:
LoginViewController *loginViewController = [[LoginViewController alloc] init];
[tabBarController presentModalViewController:loginViewController animated:YES];
相反,它会自动旋转 loginviewcontrollers 视图。
【问题讨论】:
-
+1 你的答案是我一直需要的——我的观点正在发挥作用,太令人难以置信了。我尝试通过用户界面方向发布用户界面方向通知代表,这太疯狂了。目前的模态视图控制器正是我所需要的。干杯。
标签: iphone objective-c subview uiinterfaceorientation uiwindow