0
votes

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

2
Why would you want the popup to rotate if the parent view won't? Just because it can? Or is there a use case where this would be useful? - benzado
trust me, it would be usefull for me ;) - Injectios

2 Answers

0
votes

Orientation is detected by the parent view controller. The approach I have used is in the parent view controller, detect which view is the current active view, then do your orientation based on that.

0
votes

Sorry, what you want isn't possible with standard behavior. When a childViewController supports a certain orientation, its parent and all other ViewControllers in the current hierarchy have to support that orientation as well.

What you should be doing is register the parentViewController to receive device rotation notifications, then based on those you can transform the childViewController's view. So basically your app will always remain in portrait mode but the childViewController's view will be transformed to look like it's in landscape.

Register for device orientation notifications like so

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceDidRotate:) name: UIDeviceOrientationDidChangeNotification object: nil];

Then handle it like this

// 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
}

Keep in mind that UIDeviceOrientation and UIInterfaceOrientation are reversed. UIDeviceOrientationLandscapeLeft = UIInterfaceOrientationLandscapeRight. The device was rotated to the left, so the user interface has to rotate to the right.