我一直在关注 this question 上的解决方案为了显示具有透明背景的 View 。我遇到的问题是一旦显示模态视图 Controller ,底层 View 就不再旋转。
例如,如果 A
是我的 View Controller ,那么 B
就是我的模态视图。问题如下。我目前的设备是纵向的,并且显示了 A
。然后我模态地呈现 B
。然后我旋转我的设备,B 也随之旋转,但是 A
保持原样。
请问有人可以建议如何处理这种旋转,以便底层 View (A
) 也旋转吗?
最佳答案
ModalViewController 用于中断当前的工作流程并显示一组新的 View 。因此,当您以模态方式呈现时,在这种情况下,您呈现的是 B,当前事件的 Viewcontroller 是 B 而不是 A。
ViewController 是模型- View - Controller (MVC) 设计模式中的传统 Controller 对象。他们还负责用户界面、手势识别、事件管理(例如按钮)和 View 的对齐。
当您呈现 B 时,当前 View Controller 从 A 更改为 B,因此当您尝试旋转时(如果提供了方向支持),B 的 View 会受到影响,因为它的 View Controller 处于事件状态并且它会响应旋转。通常我们不会注意到这些,因为 View 是不透明的。在您的情况下, View 是透明的,我们注意到 A 没有响应轮换。
我在 iOS6 中尝试了上面的例子(来自你提到的那个)
ViewController2 *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VC2"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:nil];
这里A保持竖屏模式
当我添加第二个 View Controller 的 View 作为 subview 时,A 变为横向
ViewController2 *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VC2"];
vc.view.backgroundColor = [UIColor clearColor];
self.view addSubview:vc.view];
发生这种情况是因为在第二次试验中,事件 View Controller 是 A 而不是 B,因为 B 的 View 是添加到 A 的 subview 。通过 Apples 的文档查看
关于iOS:将 View 旋转应用于模态视图下的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14419395/