0

UPDATED: Is it possible to have one UIViewController (vc1) as container and one UIViewController as a child (vc2)

[vs1 addChildViewController:vc2];
[vs1.view addSubview:vc2.view];

and allow orientation change in vc2 independently from vc1 supported orientations?

F.e vc1 supports only portrait orientation, but vc2 supports all orientations. I want to see vc2 view rotated to landscape meanwhile vc1 view still in portrait.

F.e I have VC1 and VC2 (popup)

Portrait

Only portrait orientation is supported for VC1, but VC2 supports all orientations.

enter image description here

I would like to have landscape orientation for popup

enter image description here

4

2 回答 2

0

方向由父视图控制器检测。我使用的方法是在父视图控制器中,检测哪个视图是当前活动视图,然后根据它进行定位。

于 2012-12-10T15:52:48.600 回答
0

抱歉,标准行为无法实现您想要的。当 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。设备向左旋转,因此用户界面必须向右旋转。

于 2012-12-10T22:13:11.373 回答