5
votes

I have been following a solution on this question in order to display a view with a transparent background. The issue that I'm having is once the modal view controller has been displayed, the underlying view doesn't get rotated anymore.

For example if A is my view controller, then B is my modal view. The issue is as follows. I currently have my device in portrait and have A displayed. I then present B modally. I then rotate my device and B rotates with it, however A stays as it was.

Please could someone advise on how to handle this rotation so that the underlying view (A) gets rotated too?

1

1 Answers

6
votes

ModalViewController is used to interrupt the current workflow and displaying a new set of views. So when you present modally, here in this case you are presenting B, the current active Viewcontroller is B and not A.

A ViewController is traditional controller objects in the Model-View-Controller (MVC) design pattern. They also take care of user interface, gesture recognitions,event management(of buttons for example) and the alignment of views in present in them.

When you presented B, the current viewcontroller changed from A to B and hence when you try to rotate(if the orientation support is provided) the view of B is effected as its the viewcontroller active and it responds to the rotation. Normally we go unnoticed these because the view is opaque. Here in your case the view is transparent and we notice that A has not responded to rotation.

I tried the above example in iOS6 (from the one you mentioned)

ViewController2 *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VC2"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:nil];

here A remained in portrait mode

When i did this adding the second viewcontroller's view as a subview, A changed to landscape

ViewController2 *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VC2"];
vc.view.backgroundColor = [UIColor clearColor];
self.view addSubview:vc.view];

this happend because in the second trial the active viewcontroller was A and not B as B's view was a subview added to A. Go through Apples's Document on