mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-05-05 01:32:59 +08:00
Removed flicker in iOS8 closes #23
This commit is contained in:
parent
d98ea66265
commit
3b7d259193
14
README.md
14
README.md
@ -82,10 +82,22 @@ Issue [#1](https://github.com/yoik/cordova-yoik-screenorientation/issues/1) @dok
|
|||||||
|
|
||||||
####iOS8
|
####iOS8
|
||||||
|
|
||||||
Versions prior to 1.2.0 will cause an application crash in iOS8.
|
Versions prior to 1.2.0 will cause an application crash in iOS8 due to a change in presentViewController timing.
|
||||||
|
|
||||||
##BB10 Notes
|
##BB10 Notes
|
||||||
|
|
||||||
Wraps the com.blackberry.app plugin functions, auto installed as a dependancy.
|
Wraps the com.blackberry.app plugin functions, auto installed as a dependancy.
|
||||||
|
|
||||||
|
#Changelog
|
||||||
|
|
||||||
|
##1.3.0
|
||||||
|
|
||||||
|
* [#23](https://github.com/yoik/cordova-yoik-screenorientation/issues/23) iOS8 flicker
|
||||||
|
|
||||||
|
##1.2.0-1.2.1
|
||||||
|
|
||||||
|
* [#19](https://github.com/yoik/cordova-yoik-screenorientation/issues/19) iOS8 Crash
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Pull requests welcome.
|
Pull requests welcome.
|
||||||
|
@ -29,4 +29,10 @@ SOFTWARE.
|
|||||||
|
|
||||||
- (void)screenOrientation:(CDVInvokedUrlCommand *)command;
|
- (void)screenOrientation:(CDVInvokedUrlCommand *)command;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface ForcedViewController : UIViewController
|
||||||
|
|
||||||
|
@property (strong, nonatomic) NSString *calledWith;
|
||||||
|
|
||||||
@end
|
@end
|
@ -27,12 +27,8 @@ SOFTWARE.
|
|||||||
|
|
||||||
-(void)screenOrientation:(CDVInvokedUrlCommand *)command
|
-(void)screenOrientation:(CDVInvokedUrlCommand *)command
|
||||||
{
|
{
|
||||||
// this method does not control the orientation, it is set in the .js file.
|
NSArray* arguments = command.arguments;
|
||||||
|
NSString* orientationIn = [arguments objectAtIndex:1];
|
||||||
// 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.
|
|
||||||
[self.viewController presentViewController:[UIViewController new] animated:NO completion:nil];
|
|
||||||
[self.viewController dismissViewControllerAnimated:NO completion:nil];
|
|
||||||
|
|
||||||
// grab the device orientation so we can pass it back to the js side.
|
// grab the device orientation so we can pass it back to the js side.
|
||||||
NSString *orientation;
|
NSString *orientation;
|
||||||
@ -53,10 +49,46 @@ SOFTWARE.
|
|||||||
orientation = @"portait";
|
orientation = @"portait";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
|
||||||
messageAsDictionary:@{@"device":orientation}];
|
|
||||||
|
|
||||||
|
if ([orientationIn isEqual: @"unlocked"]) {
|
||||||
|
orientationIn = orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we send the result prior to the view controller presentation so that the JS side
|
||||||
|
// is ready for the unlock call.
|
||||||
|
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
||||||
|
messageAsDictionary:@{@"device":orientation}];
|
||||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
[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];
|
||||||
|
vc.calledWith = orientationIn;
|
||||||
|
|
||||||
|
// backgound should be transparent as it is briefly visible
|
||||||
|
// prior to closing.
|
||||||
|
vc.view.backgroundColor = [UIColor clearColor];
|
||||||
|
// vc.view.alpha = 0.0;
|
||||||
|
vc.view.opaque = YES;
|
||||||
|
// This stops us getting the black application background flash, iOS8
|
||||||
|
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
||||||
|
|
||||||
|
[self.viewController presentViewController:vc animated:NO completion:nil];
|
||||||
|
[self.viewController dismissViewControllerAnimated:NO completion:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation ForcedViewController
|
||||||
|
|
||||||
|
- (NSUInteger) supportedInterfaceOrientations
|
||||||
|
{
|
||||||
|
if ([self.calledWith rangeOfString:@"portrait"].location != NSNotFound) {
|
||||||
|
return UIInterfaceOrientationMaskPortrait;
|
||||||
|
} else if([self.calledWith rangeOfString:@"landscape"].location != NSNotFound) {
|
||||||
|
return UIInterfaceOrientationMaskLandscape;
|
||||||
|
}
|
||||||
|
return UIInterfaceOrientationMaskAll;
|
||||||
|
}
|
||||||
@end
|
@end
|
@ -17,10 +17,9 @@ screenOrientation.setOrientation = function(orientation) {
|
|||||||
var success = function(res) {
|
var success = function(res) {
|
||||||
if (orientation === 'unlocked' && res.device) {
|
if (orientation === 'unlocked' && res.device) {
|
||||||
iosOrientation = res.device;
|
iosOrientation = res.device;
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
iosOrientation = 'unlocked';
|
iosOrientation = 'unlocked';
|
||||||
},0);
|
},300);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user