uiviewcontroller - UIModalPresentationCurrentContext - 未调用旋转方法

标签 uiviewcontroller rotation transparent uimodalpresentationstyle

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

UIViewController *transparentViewController = [[UIViewController alloc] init];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:transparentViewController animated:NO completion:^{
}];

但是,当我在 VC 被插入后旋转设备时,旋转看起来完全一团糟。它不是干净地旋转而是尴尬地拉伸(stretch) View 以适应新的方向。

此外,当我将 transparentViewController 子类化时,我发现它的 viewwillautorotate 方法没有被调用! (即使它以困惑的动画方式旋转)

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

最佳答案

我认为这个问题与原始 View Controller 无法旋转有关,因此您的模态视图 Controller 也被阻止旋转。要解决这个问题,您可以渲染原始 UIViewControllerCALAyer进入 UIImage使用 renderInContext方法。然后你可以把它放在 UIImageView在模态视图 Controller 中 View 层次结构的底部。这将产生 View Controller 看起来透明的效果,因为您在假静态图像中看到它背后的内容。那么当UIViewController旋转您可以手动应用 CGAffineTransformUIImageView让背景保持在原位,而其顶部的内容可以自由旋转。

关于uiviewcontroller - UIModalPresentationCurrentContext - 未调用旋转方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14883434/

相关文章:

jQuery 调整旋转元素的大小

iphone - iphone设置透明状态栏的方法

html - 透明gif不透明?

iphone - 如何在UITabBarController中的两个UIViewController之间传递信息

iphone - 实现下拉刷新 View 功能

ios - iPhone X home 指示灯调光/不调光

Java2D 旋转后图像质量丢失

ios - UIViewController 中的初始化问题

ios - iPhone 的纵向高度 - 'Regular' ,上下颠倒一个 - 'Compact' - 为什么?

android - 更改 android numberpicker 分隔线颜色