Undo Undo - 4 months ago 7x
iOS Question

Detect rotation changes in iOS

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.


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.