Detect rotation changes in iOS

Undo picture Undo · Jan 16, 2013 · Viewed 24k times · Source

I am making an iOS app that needs to do a little interface rearrangement upon rotation. I am trying to detect this by implementing - (void)orientationChanged:(NSNotification *)note, but this gives me notifications for when the device is face up or face down.

I want a way to just get notified when the interface changes orientations.

Answer

Levi picture Levi · Jan 16, 2013

There are several method where you can do that, you can find them in the UIViewController class reference:

– willRotateToInterfaceOrientation:duration:
– willAnimateRotationToInterfaceOrientation:duration:
– didRotateFromInterfaceOrientation:

You could also do it in the viewWillLayoutSubviews method, but be careful with it, because it is called on the screen appearance too, and whenever you add a subview.

Edit:

Solution now deprecated, see accepted answer.