UIModalPresentationCurrentContext - 未调用旋转方法

Zac*_*hel 6 rotation transparent uiviewcontroller uimodalpresentationstyle

我正在尝试使用UIModalPresentationCurrentContext在VC之上呈现VC,以便查看其背后的视图.以下代码有效:

UIViewController *transparentViewController = [[UIViewController alloc] init];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:transparentViewController animated:NO completion:^{
}];
Run Code Online (Sandbox Code Playgroud)

但是,当我按下VC后旋转设备时,旋转看起来完全搞砸了.它不是干净地旋转,而是笨拙地拉伸视图以适应新的方向.

此外,当我继承透明ViewController时,我发现它的viewwillautorotate方法没有被调用!(即使它以混乱的动画方式旋转)

UIModalPresentationCurrentContext样式是不是要旋转?有没有办法解决?还有其他人遇到过这个问题吗?

DHa*_*ick 0

我认为该问题与原始视图控制器无法旋转有关,因此您的模态视图控制器也被阻止旋转。为了解决这个问题,您可以使用该方法将原始的UIViewController' '渲染CALAyer为 a 。然后,您可以将其放置在模态视图控制器中视图层次结构的底部。这将使视图控制器显示为透明,因为您可以在假静态图像中看到其背后的内容。然后,当旋转时,您可以手动将 a 应用于以使背景保持在原位,而其顶部的内容可以自由旋转。UIImagerenderInContextUIImageViewUIViewControllerCGAffineTransformUIImageView