科尔多瓦的iOS更改屏幕方向为横向单页 [英] Cordova iOS Change Screen Orientation To Landscape on a Single Page

查看:130
本文介绍了科尔多瓦的iOS更改屏幕方向为横向单页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在科尔多瓦3+开发的iPhone应用程序。目前该应用程序运行正常。我也限制了当前应用的横向视图,即应用程序只显示在肖像。

I have an app developed in Cordova 3+ for iPhone. currently the application is running fine. I have also restricted the Landscape view of the current application, ie the application display only in portrait.

应用程序包含了很多说明和报告的页面。我想要的是显示在纵向的所有页面,并显示在景观上的报告页。

App consists of a lot of description and a report page. What i want is to display all pages in portrait and display the reports page in Landscape.

荫使用Backbone.js的+ underscore.js框架。

Iam using Backbone.js + underscore.js framework.

不要任何人有这个任何建议或解决方案?

Do anyone have any suggestion or solution for this?

在此先感谢!

编辑:我想是强制特定的报表页面来显示横向视图。并在画像显示所有其他网页。

编辑:通过编程控制屏幕方向在iPhone的科尔多瓦3 +

推荐答案

不过,我找不到任何解决方案。 Atlast我使用CSS来实现它。

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.

你可以在一个页面使用本地code编程改为横向,并通过使用javascript调用它。

创建一个新的js文件作为ScreenOrientation.js并插入低于code,

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]);
}
};

和index.html中添加上述文件,如下,

and add the above file in index.html as below,

<script type="text/javascript" src="ScreenOrientation.js"></script>

添加下面的功能添加任何js文件(在我的项目我添加了一个的script.js文件来添加常用功能),

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) {
}

在config.xml中添加下面根据功能名称,

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>

在插件增加(对科尔多瓦&LT; 3.0),

Under Plugins add (For cordova < 3.0),

<plugins>
    <plugin name="ScreenOrientation" value="ScreenOrientation" />
</plugins>

在科尔多瓦项目>插件点击右键并选择新的文件,然后从iOS的选择可可触摸然后选择Objective-C类,然后单击下一步,在类名插入ScreenOrientation,并在CDVPlugin的子类,点击下一步,然后点击创建。

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.

在ScreenOrientation.h输入下面,

Enter the below in ScreenOrientation.h,

#import <Cordova/CDV.h>

@interface ScreenOrientation : CDVPlugin

- (void) screenorientationFunction:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;

@end

在ScreenOrientation.m输入下面,

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

在科尔多瓦项目点击搜索,然后搜索shouldAutoRotate,找到下面和改变返回,在默认情况下这将是'YES'将其更改为NO。

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');

这篇关于科尔多瓦的iOS更改屏幕方向为横向单页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆