简体   繁体   English

容器视图控制器中的力方向更改

[英]Force orientation change in container view controller

I've created a container view controller in which I can embed a child view controller (using the new iOS 5 API). 我创建了一个容器视图控制器,可以在其中嵌入子视图控制器(使用新的iOS 5 API)。 When a child view controller is embedded that only supports the portrait orientation, and the device is currently in landscape orientation, I want to force a rotation to portrait. 当嵌入的子视图控制器仅支持纵向时,并且设备当前处于横向时,我想强制旋转为纵向。

I found the [UIViewController attemptRotationToDeviceOrientation] method which almost does this, but not quite. 我发现[UIViewController attemptRotationToDeviceOrientation]方法几乎可以做到这一点,但是效果却不尽如人意。 It actually works the opposite way, so that if the child view controller is embedded, and the device is in portrait orientation, I can rotate to landscape (but the view controller will remain portrait), then dismiss the embedded view controller, and it will automatically rotate to landscape. 实际上,它的工作方式相反,因此,如果子视图控制器是嵌入式的,并且设备处于纵向,则可以旋转到横向(但视图控制器将保持纵向),然后关闭嵌入式视图控制器,它将自动旋转到风景。

Is there any way to force the container view controller to rotate when embedding a child view controller that doesn't support the current orientation? 嵌入不支持当前方向的子视图控制器时,有什么方法可以强制容器视图控制器旋转?

I'll bet money this isn't a satisfying answer, BUT...I think you have to abandon rotation and move to an affine transform (of the subview) of 90 degrees. 我敢打赌,这不是一个令人满意的答案,但是...我认为您必须放弃旋转,转而使用90度的仿射变换(子视图)。 Rotation is a physical act of the user, and try as we might we can't actually rotate the device. 旋转是用户的身体行为,请尝试尝试我们实际上无法旋转设备。 However, a transform is within your power. 但是,变换是您的能力之内。 You can always set it back to the identity once the user complies and rotates the device to the proper orientation. 用户合并将设备旋转到正确的方向后,您始终可以将其重新设置为身份。

Have fun & good luck, 祝您好运,

Damien 达米安

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM