问题
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