mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-05-05 01:32:59 +08:00
make iOS rotate as needed when lockOrientation is called
This commit is contained in:
parent
ff0d1fbfc5
commit
ec3e90dbc8
31
src/ios/CDVViewController+UpdateSupportedOrientations.h
Normal file
31
src/ios/CDVViewController+UpdateSupportedOrientations.h
Normal 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
|
35
src/ios/CDVViewController+UpdateSupportedOrientations.m
Normal file
35
src/ios/CDVViewController+UpdateSupportedOrientations.m
Normal 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
|
@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#import <Cordova/CDVPlugin.h>
|
#import <Cordova/CDVPlugin.h>
|
||||||
|
#import <Cordova/CDVViewController.h>
|
||||||
|
|
||||||
@interface YoikScreenOrientation : CDVPlugin
|
@interface YoikScreenOrientation : CDVPlugin
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#import "YoikScreenOrientation.h"
|
#import "YoikScreenOrientation.h"
|
||||||
|
#import "CDVViewController+UpdateSupportedOrientations.h"
|
||||||
|
|
||||||
@implementation YoikScreenOrientation
|
@implementation YoikScreenOrientation
|
||||||
|
|
||||||
@ -61,9 +62,8 @@
|
|||||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||||
|
|
||||||
// SEE https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation
|
// 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
|
// HACK: Force rotate by changing the view hierarchy.
|
||||||
// This has been changed substantially since iOS8 broke it...
|
ForcedViewController *vc = [[ForcedViewController alloc] init];
|
||||||
ForcedViewController *vc = [[ForcedViewController alloc] init];
|
|
||||||
vc.calledWith = orientationIn;
|
vc.calledWith = orientationIn;
|
||||||
|
|
||||||
// backgound should be transparent as it is briefly visible
|
// backgound should be transparent as it is briefly visible
|
||||||
@ -78,12 +78,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[self.viewController presentViewController:vc animated:NO completion:^{
|
[self.viewController presentViewController:vc animated:NO completion:nil];
|
||||||
// added to support iOS8 beta 5, @see issue #19
|
|
||||||
dispatch_after(0, dispatch_get_main_queue(), ^{
|
|
||||||
[self.viewController dismissViewControllerAnimated:NO completion:nil];
|
|
||||||
});
|
|
||||||
}];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}];
|
}];
|
||||||
@ -93,6 +88,20 @@
|
|||||||
|
|
||||||
@implementation ForcedViewController
|
@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
|
- (UIInterfaceOrientationMask) supportedInterfaceOrientations
|
||||||
{
|
{
|
||||||
if ([self.calledWith rangeOfString:@"portrait"].location != NSNotFound) {
|
if ([self.calledWith rangeOfString:@"portrait"].location != NSNotFound) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user