viewWillLayoutSubviews 和旋转 [英] viewWillLayoutSubviews and rotation
问题描述
在我的应用程序中,我将所有视图定位在 viewWillLayoutSubviews 中.最近我被要求让应用程序处理所有方向.我认为这很简单,因为我正在使用
In my app I am positioning all of my views in viewWillLayoutSubviews. Recently I been asked to make the app handle all orientations. I figured that would be simple because I was using
CGRectrotatedFrame = [self.view convertRect:self.view.frame fromView:nil];
这将返回与设备当前方向匹配的框架.不幸的是,我发现这并不适用于所有情况.也就是说,如果我呈现一个模态视图控制器,将它旋转到横向然后关闭它,父视图控制器rotatedFrame"不是我所期望的.这导致我的视图布局不正确.
Which would return a frame that matches the device current orientation. Unfortunately I found that this does not work for all situations. Namely if I present a modal viewcontroller, rotate it to landscape and then dismiss it, the parent viewcontroller 'rotatedFrame' is not what I expected. This causes my view be layout incorrectly.
有没有办法获得正确的方向框架?
Is there a way to get the correct orientation frame?
推荐答案
我发现,不是将 nil
放在 fromView:
中,而是使用视图的父级它按预期工作.
I found that instead of putting nil
for the fromView:
I use the parent of the view that it works as expected.
CGRectrotatedFrame = [self.view convertRect:self.view.frame fromView:self.view.superview];
这篇关于viewWillLayoutSubviews 和旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!