make iOS rotate as needed when lockOrientation is called

This commit is contained in:
Tony Homer 2016-04-22 10:55:44 -04:00
parent ff0d1fbfc5
commit ec3e90dbc8
4 changed files with 85 additions and 9 deletions

View File

@ -0,0 +1,31 @@
/*
The MIT License (MIT)
Copyright (c) 2014
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#import <Cordova/CDVViewController.h>
@interface CDVViewController (UpdateSupportedOrientations)
- (void)updateSupportedOrientations:(NSArray *)orientations;
@end

View File

@ -0,0 +1,35 @@
/*
The MIT License (MIT)
Copyright (c) 2014
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#import "CDVViewController+UpdateSupportedOrientations.h"
@implementation CDVViewController (UpdateSupportedOrientations)
- (void)updateSupportedOrientations:(NSArray *)orientations {
[self setValue:orientations forKey:@"supportedOrientations"];
}
@end

View File

@ -20,6 +20,7 @@
*/
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVViewController.h>
@interface YoikScreenOrientation : CDVPlugin

View File

@ -20,6 +20,7 @@
*/
#import "YoikScreenOrientation.h"
#import "CDVViewController+UpdateSupportedOrientations.h"
@implementation YoikScreenOrientation
@ -61,9 +62,8 @@
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
// SEE https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation
// HACK: Force rotate by changing the view hierarchy. Present modal view then dismiss it immediately
// This has been changed substantially since iOS8 broke it...
ForcedViewController *vc = [[ForcedViewController alloc] init];
// HACK: Force rotate by changing the view hierarchy.
ForcedViewController *vc = [[ForcedViewController alloc] init];
vc.calledWith = orientationIn;
// backgound should be transparent as it is briefly visible
@ -78,12 +78,7 @@
#endif
dispatch_async(dispatch_get_main_queue(), ^{
[self.viewController presentViewController:vc animated:NO completion:^{
// added to support iOS8 beta 5, @see issue #19
dispatch_after(0, dispatch_get_main_queue(), ^{
[self.viewController dismissViewControllerAnimated:NO completion:nil];
});
}];
[self.viewController presentViewController:vc animated:NO completion:nil];
});
}];
@ -93,6 +88,20 @@
@implementation ForcedViewController
-(void) viewDidAppear:(BOOL)animated {
CDVViewController *presenter = (CDVViewController*)self.presentingViewController;
if ([self.calledWith rangeOfString:@"portrait"].location != NSNotFound) {
[presenter updateSupportedOrientations:@[[NSNumber numberWithInt:UIInterfaceOrientationPortrait]]];
} else if([self.calledWith rangeOfString:@"landscape"].location != NSNotFound) {
[presenter updateSupportedOrientations:@[[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft], [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight]]];
} else {
[presenter updateSupportedOrientations:@[[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft], [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight], [NSNumber numberWithInt:UIInterfaceOrientationPortrait]]];
}
[presenter dismissViewControllerAnimated:NO completion:nil];
}
- (UIInterfaceOrientationMask) supportedInterfaceOrientations
{
if ([self.calledWith rangeOfString:@"portrait"].location != NSNotFound) {