Search code examples
iphonelayoutrotationorientationautoresize

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?


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.