diff --git a/src/ios/CDVOrientation.h b/src/ios/CDVOrientation.h index 48166a3..7e38d6f 100644 --- a/src/ios/CDVOrientation.h +++ b/src/ios/CDVOrientation.h @@ -24,7 +24,10 @@ #import @interface CDVOrientation : CDVPlugin -{} +{ +@protected + UIInterfaceOrientation _lastOrientation; +} - (void)screenOrientation:(CDVInvokedUrlCommand *)command; diff --git a/src/ios/CDVOrientation.m b/src/ios/CDVOrientation.m index c7704e4..a96b02d 100644 --- a/src/ios/CDVOrientation.m +++ b/src/ios/CDVOrientation.m @@ -55,17 +55,25 @@ if ([UIDevice currentDevice] != nil){ NSNumber *value = nil; - if(orientationMask == 8 || orientationMask == 12) { - value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight]; - } else if (orientationMask == 4){ - value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]; - } else if (orientationMask == 1 || orientationMask == 3) { - value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; - } else if (orientationMask == 2) { - value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown]; + if (orientationMask != 15) { + _lastOrientation = [UIApplication sharedApplication].statusBarOrientation; + if(orientationMask == 8 || orientationMask == 12) { + value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight]; + } else if (orientationMask == 4){ + value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]; + } else if (orientationMask == 1 || orientationMask == 3) { + value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; + } else if (orientationMask == 2) { + value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown]; + } + } else { + if (_lastOrientation != nil) { + value = [NSNumber numberWithInt:_lastOrientation]; + } } if (value != nil) { [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; + [UINavigationController attemptRotationToDeviceOrientation]; } }