iOS:将视图旋转应用于模态视图下的视图控制器 [英] iOS: Apply view rotation to view controller under modal view

查看:112
本文介绍了iOS:将视图旋转应用于模态视图下的视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注这个问题的解决方案以显示具有透明背景的视图。我遇到的问题是,一旦显示模态视图控制器,基础视图就不再旋转了。

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.

例如,如果 A 是我的视图控制器,然后 B 是我的模态视图。问题如下。我目前的设备是纵向的,并显示 A 。然后我以模态方式呈现 B 。然后我旋转我的设备,B随之旋转,但 A 保持不变。

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.

请有人可以提供建议如何处理这种旋转,以便底层视图( A )也被旋转?

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

推荐答案

ModalViewController用于中断当前工作流并显示一组新视图。因此,当您以模态方式呈现时,在这种情况下,您呈现B,当前活动的Viewcontroller是B而不是A.

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.

ViewController是模型中的传统控制器对象 - 视图 - 控制器(MVC)设计模式。他们还负责用户界面,手势识别,事件管理(例如按钮)以及当前视图的对齐。

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.

当您呈现B时,当前的视图控制器从A更改为B,因此当您尝试旋转时(如果提供了方向支持),B的视图将作为它的viewcontroller是活动的,它响应旋转。通常我们会忽略这些因为视图是不透明的。在您的情况下,视图是透明的,我们注意到A没有响应旋转。

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.

我在iOS6中试过上面的例子(来自你提到的那个)

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];

此处A保持纵向模式

当我这样做时,将第二个viewcontroller的视图添加为子视图,A更改为横向

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];

发生这种情况是因为在第二次试用中,活动视图控制器是A而不是B,因为B的视图是子视图添加到A.浏览Apples的文档

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

  • About ViewController
  • About windows and views
  • Presenting ViewControllers

这篇关于iOS:将视图旋转应用于模态视图下的视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆