In my working application (iOS 7.0.1), UIDeviceOrientationDidChangeNotification
is called.
Now when i run this application in iOS 8.0 UIDeviceOrientationDidChangeNotification
is not getting called.
Tried a lot but no luck.
EDIT-1:
I have use below code to add observer for orientation change. Works perfect in iOS 7. No luck for iOS 8.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
In my case, after lot of searches I found that I'd made a silly mistake, that my device potrait orientation lock is on.
Please confirm the device orientation lock off in the settings.
This may help someone.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotateDeviceChangeNotification:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
>
-(void)didRotateDeviceChangeNotification:(NSNotification *)notification
{
UIInterfaceOrientation newOrientation = [UIApplication sharedApplication].statusBarOrientation;
if ((newOrientation == UIInterfaceOrientationLandscapeLeft || newOrientation == UIInterfaceOrientationLandscapeRight))
{
}
}
Swift 3:
Add observer to UIDeviceOrientationDidChange in viewDidLoad
NotificationCenter.default.addObserver(self, selector: #selector(orientationChanged), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
Selector method is like this:
func orientationChanged(notification: Notification) {
}
Don't forget to add Remove observer on deinit method
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With