viewWillLayoutSubviews and rotation

风格不统一 提交于 2020-01-16 18:38:28

问题


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

CGRect rotatedFrame = [self.view convertRect:self.view.frame fromView:nil];

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?


回答1:


I found that instead of putting nil for the fromView: I use the parent of the view that it works as expected.

CGRect rotatedFrame = [self.view convertRect:self.view.frame fromView:self.view.superview];



来源:https://stackoverflow.com/questions/16967483/viewwilllayoutsubviews-and-rotation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!