However i couldn't find any solutions. Atlast i achieved it using CSS.
-ms-transform:rotate(-90deg); /* IE 9 */
-webkit-transform:rotate(-90deg); /* Chrome, Safari, Opera */
transform:rotate(-90deg); /* Standard syntax */
Anyway it not a perfect solution but it works.
And you can programatically change a single page to landscape using native code and call it via using javascript.
Create a new js file as ScreenOrientation.js and insert the below code,
var ScreenOrientation = {
//alert(orientation);
callScreenOrientationNative: function(success,fail,orientation) {
return Cordova.exec( success, fail,
"ScreenOrientation",
"screenorientationFunction",
[orientation]);
}
};
and add the above file in index.html as below,
<script type="text/javascript" src="ScreenOrientation.js"></script>
Add the below function in any added js file(in my project i have added a script.js file to add common functions),
function callScreenOrientation(orientation) {
ScreenOrientation.callScreenOrientationNative(nativePluginResultHandler,nativePluginErrorHandler,orientation);
}
function nativePluginResultHandler (result) {
}
function nativePluginErrorHandler (error) {
}
In config.xml add the below under feature name,
<!-- Screen Orientation custom plugin to display reports page. -->
<feature name="ScreenOrientation">
<param name="ios-package" value="ScreenOrientation"/>
</feature>
Under Plugins add (For cordova < 3.0),
<plugins>
<plugin name="ScreenOrientation" value="ScreenOrientation" />
</plugins>
On Cordova projects > Plugins right click and select new file, then from iOS select Cocoa touch then Select objective-C Class and click next, in class name insert "ScreenOrientation" and in Subclass of "CDVPlugin" and click next and click create.
Enter the below in ScreenOrientation.h,
#import <Cordova/CDV.h>
@interface ScreenOrientation : CDVPlugin
- (void) screenorientationFunction:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
@end
Enter the below in ScreenOrientation.m,
#import "ScreenOrientation.h"
@implementation ScreenOrientation
- (void) screenorientationFunction:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
[arguments pop];
NSString *orientation = [arguments objectAtIndex:0];
if ( [orientation isEqualToString:@"LandscapeLeft"] ) {
NSLog(@"Landscape Left");
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft];
}
else if ( [orientation isEqualToString:@"LandscapeRight"] ) {
NSLog(@"Landscape Right");
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight];
}
else if ( [orientation isEqualToString:@"Portrait"] ) {
NSLog(@"Portrait");
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait];
}
else if ( [orientation isEqualToString:@"PortraitUpsideDown"] ) {
NSLog(@"Portrait upSide Down Left");
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortraitUpsideDown];
}
}
@end
In Cordova project click search and search for "shouldAutoRotate and find the below and change the return, by default it will be 'YES' change it to 'NO'.
CDVViewController.m
- (BOOL)shouldAutorotate
{
return NO;
}
And in project settings, in Device orientations check all options (not important though),
Project Settings > Device orientation > Tick all 4 options.
and call it from your project like this,
callScreenOrientation('LandscapeLeft');
callScreenOrientation('LandscapeRight');
callScreenOrientation('Portrait');
callScreenOrientation('PortraitUpsideDown');