1
votes

on iPad ios 9+, with objective-c : - lock the orientation outside of your app - in code: how to detect when the device changes the orientation?

I have tried all possibilities:

1) try to catch UIDeviceOrientationDidChangeNotification event:

- (void)subscribeOrientationChangeEvent {

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(orientationChanged:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:[UIDevice currentDevice]];
}

- (void) orientationChanged:(NSNotification *)note {

     NSLog("Device rotated");
}

2) override viewWillTransitionToSize method

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator
{
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    NSLog("Device rotated");
}

3) use KVO to see if the value orientation of [UIDevice currentDevie]

4) use KVO to see if the value statusBarOrientation of [UIApplication sharedApplication]

5) set Require FullScreen for the setting StatusBarStyle

reference: link

apply this setting and combine with all above attempts, but all failed.

6) using Accelerometer (CMMotionManager)

Any advice? thanks a lot

1
Try with detecting when the device return from locked state, then check for new orientation.Duyen-Hoa
it's not my purpose.chipbk10

1 Answers

0
votes

If the device orientation is lock; your app will have to abide by it. You won't be able to detect orientation for obvious reasons. So the short answer is you can't.