UIInterfaceOrientation 子视图中的旋转不起作用
在我的应用程序中,我使用 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 视图。
In my App I use a UITabbarController, which rotates perfectly to all UIInterfaceOrientations in all viewcontrollers. But when I add an UIView to the UIWindow afterwards it will not be added in the current UIInterfaceOrientation, but always in UInterfaceOrientationPortrait (which is default for the app). It won't rotate to a new orientation also. I add the ViewController by using:
LoginViewController *loginViewController = [[LoginViewController alloc] init];
[self.window addSubview:[loginViewController view]];
I have
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
NSLog(@"%@", @"YES IT WILL!");
}
in LoginViewController.m but there will never be logged anything. Any idea why the subview won't rotate?
SideSwipe
EDIT:
Found the solution:
Apparently UIWindow should only have one subview, not more, otherwise things will mess up, so i call:
LoginViewController *loginViewController = [[LoginViewController alloc] init];
[tabBarController presentModalViewController:loginViewController animated:YES];
instead, which will autorotate the loginviewcontrollers view just fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在另一个视图中有一个视图,当发生旋转时,只有父
willRotateToInterfaceOrientation
被调用,所以我所做的是添加[self.subViewController willRotateToInterfaceOrientation:toInterfaceOrientationuration:duration];
到父级的willRotateToInterfaceOrientation
方法。I have a view inside another view, when rotation happened, only the parent
willRotateToInterfaceOrientation
got called, so what I did is add[self.subViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
to parent'swillRotateToInterfaceOrientation
method.当您向窗口添加新的子视图时,您也必须使窗口旋转。
As you are adding a new subview to window, you have to make the window rotate too.