Question

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?

Was it helpful?

Solution

I think you can try overriding layoutSubviews. There you can layout the subviews in accordance with the current orientation, without bothering about will/did RotateFromInterfaceOrientation. layoutSubviews is called every time the views are laid out. This shall help you in timing your frame changes with the animation.

HTH,

Akshay

OTHER TIPS

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top