mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-04-24 03:00:11 -04:00
The status bar and screen will be rotated with animation to the desired
orientation.
To use the AppDelegate must have the main view controller that extends
CDVViewController as a member variable called viewController.
This main view controller must also have the following modifications.
Header file should have the below allowed orientations variable
introduced.
@interface MainViewController : CDVViewController {
NSMutableArray *allowedOrientations;
}
@property (nonatomic, retain) NSMutableArray *allowedOrientations;
Source file should have the allowedOrientations synthesized.
@synthesize allowedOrientations;
Then perform setup in viewDidLoad method. UIDeviceOrientationPortrait
can be replaced with UIDeviceOrientationLandscapeRight depending on
desired start up orientation.
- (void) viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.allowedOrientations = [NSMutableArray array];
[self.allowedOrientations addObject:[NSNumber
numberWithInt:UIDeviceOrientationPortrait]];
}
Finally implement shouldAutorotateToInterfaceOrientation method with
the following.
- (BOOL)
shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
Orientation
{
// Return YES for supported orientations
return [allowedOrientations containsObject:[NSNumber
numberWithInt:interfaceOrientation]];
}
9 lines
271 B
JavaScript
Executable File
9 lines
271 B
JavaScript
Executable File
var screenOrientation = function() {}
|
|
|
|
screenOrientation.prototype.set = function(str, success, fail) {
|
|
var args = {};
|
|
args.key = str;
|
|
PhoneGap.exec(success, fail, "ScreenOrientation", "set", [args]);
|
|
};
|
|
navigator.screenOrientation = new screenOrientation();
|