Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS8 + UIDeviceOrientationDidChangeNotification not getting called

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];
like image 264
Kampai Avatar asked Sep 30 '14 06:09

Kampai


3 Answers

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.

like image 79
Nazik Avatar answered Nov 11 '22 04:11

Nazik


[[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))
    {

    }
}
like image 24
iGW Avatar answered Nov 11 '22 06:11

iGW


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)
like image 1
Blaze Avatar answered Nov 11 '22 04:11

Blaze