[英]UIViewController container: allow different orientations for childs
更新:是否可以将一个UIViewController
( vc1
)作为容器并将一个UIViewController
作为子vc2
( vc2
)
[vs1 addChildViewController:vc2];
[vs1.view addSubview:vc2.view];
并允许vc2
方向更改独立于vc1
支持的方向?
Fe vc1
仅支持纵向方向,而vc2
支持所有方向。 我想看到vc2
视图旋转为横向,而vc1
视图仍为纵向。
Fe我有VC1和VC2(弹出窗口)
VC1仅支持纵向方向,而VC2支持所有方向。
我想让横向显示弹出窗口
方向由父视图控制器检测。 我使用的方法是在父视图控制器中,检测哪个视图是当前活动视图,然后根据该方向进行定向。
抱歉,标准行为无法实现您想要的。 当childViewController支持某个方向时,其父级和当前层次结构中的所有其他ViewController也必须支持该方向。
您应该做的是注册parentViewController来接收设备旋转通知,然后根据这些通知可以转换childViewController的视图。 因此,基本上,您的应用程序将始终保持纵向模式,但是childViewController的视图将被转换为看起来像是横向的。
注册设备定向通知,如下所示
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceDidRotate:) name: UIDeviceOrientationDidChangeNotification object: nil];
然后这样处理
// This method gets called everytime the device (!), not the viewController rotates
-(void)deviceDidRotate: (NSNotification*) notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
// Animate the transform here based on the orientation
}
请记住,UIDeviceOrientation和UIInterfaceOrientation是相反的。 UIDeviceOrientationLandscapeLeft = UIInterfaceOrientationLandscapeRight。 该设备向左旋转,因此用户界面必须向右旋转。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.