Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the correct frame inside willRotateToInterfaceOrientation

My subviews have different layout when in portrait and landscape orientation. The layout is based on the frame of the superview, and is not trivial (can't be achieved using autoresizing springs and struts).

The problem is that if i'm changing the frame of the subViews during willRotateToInterfaceOrientation, the animation is correct, but the frame is the superView is still the frame from the old orientation.

If i'm changing the subViews during didRotateFromInterfaceOrientation, the frame is the superView is indeed the correct one, but the frame change only occurs after the rotating animation and it doesn't look good.

What is the correct way to change the frames of the subViews when changing orientation?

like image 619
adamsiton Avatar asked Sep 11 '11 08:09

adamsiton


1 Answers

This function works for what you need because the views frame has changed from the rotation and it doesn't stall the custom animation.

-(void)willAnimateRotationToInterfaceOrientation (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    float width = UIInterfaceOrientationIsPortrait(toInterfaceOrientation) ? [[UIScreen mainScreen] applicationFrame].size.width : [[UIScreen mainScreen] applicationFrame].size.height;
//do something with the width now
//or you can get the height the same way
}
like image 86
Dash Avatar answered Oct 03 '22 08:10

Dash