iOS: Apply view rotation to view controller under modal view

人盡茶涼 提交于 2019-12-05 10:10:29

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!