我有一个包含两个 View 的 GLKViewController
:一个 GLKView
和一个显示一些命令的透明 UIView
。
GLKViewController
支持两种设备方向:纵向和横向。
当设备从纵向旋转到横向时,我想:
- 不旋转 GLKView;
- 使用命令旋转覆盖的 UIView。
基本上 GLKView 应该始终保持纵向,而另一个 View 应该遵循设备方向。
GLKViewController 在 NavigationController 中。要么我需要让 NavigationController 横向旋转,要么我需要实现一个假的导航栏并以编程方式执行“弹出”。
我看到了一个简单地旋转 View 的解决方案(在收到通知后),但我想保持动画旋转该 View 。
我尝试使用另一个 UIViewController 子类,接收 GLKViewController 和 View 作为两个子 UIViewController 的命令,但它不起作用:屏幕保持黑色。
最佳答案
当涉及到 UINavigationController 时,在 UINavigationController 上创建一个类别并覆盖 supportedInterfaceOrientations。
#import "UINavigationController+Orientation.h"
@implementation UINavigationController (Orientation)
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate
{
return YES;
}
@end
现在,iOS 容器(例如 UINavigationController)不会咨询它们的子容器来确定它们是否应该自动旋转。
如何创建类别
添加一个新文件(cocoa touch下的Objective c-类别)
类别:UINavigationController 上的方向
将以上代码添加到UINavigationController+Orientation.m
关于ios - 在 UIViewController 中仅旋转一个 UIView(两个中的一个),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22077505/