iOS 6 - How to run custom code when orientation changes iOS 6 - How to run custom code when orientation changes xcode xcode

iOS 6 - How to run custom code when orientation changes


Listen for device orientation changes:

[[NSNotificationCenter defaultCenter]        addObserver:self          selector:@selector(deviceOrientationDidChangeNotification:)               name:UIDeviceOrientationDidChangeNotification             object:nil];

When notified, get the device orientation from UIDevice:

- (void)deviceOrientationDidChangeNotification:(NSNotification*)note{    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];    switch (orientation)    {        // etc...     }}