但是我无法找到任何解决方案。 Atlast我使用CSS实现了它。
-ms-transform:rotate(-90deg); /* IE 9 */
-webkit-transform:rotate(-90deg); /* Chrome, Safari, Opera */
transform:rotate(-90deg); /* Standard syntax */
无论如何,它不是一个完美的解决方案,但它的工作原理。
而且您可以使用本地代码以编程方式将单个页面更改为风景,并通过使用javascript调用它。
创建一个新的js文件作为ScreenOrientation.js并插入下面的代码,
var ScreenOrientation = {
//alert(orientation);
callScreenOrientationNative: function(success,fail,orientation) {
return Cordova.exec(success, fail,
"ScreenOrientation",
"screenorientationFunction",
[orientation]);
}
};
和index.html中添加上述文件,如下,
<script type="text/javascript" src="ScreenOrientation.js"></script>
添加以下功能在任何添加的js文件中(在我的项目中,我添加了script.js文件以添加常用功能),
function callScreenOrientation(orientation) {
ScreenOrientation.callScreenOrientationNative(nativePluginResultHandler,nativePluginErrorHandler,orientation);
}
function nativePluginResultHandler (result) {
}
function nativePluginErrorHandler (error) {
}
在config.xml中添加以下下的功能名称,
<!-- Screen Orientation custom plugin to display reports page. -->
<feature name="ScreenOrientation">
<param name="ios-package" value="ScreenOrientation"/>
</feature>
在插件增加(对科尔多瓦< 3.0),
<plugins>
<plugin name="ScreenOrientation" value="ScreenOrientation" />
</plugins>
在科尔多瓦项目>插件点击右键并选择新的文件,然后从iOS选择Cocoa touch,然后选择objective-C Class,然后单击下一步,在类名称中插入“ScreenOrientation”和“CDVPlugin”的子类,然后单击下一步并单击create。
在ScreenOrientation.h输入下面,
#import <Cordova/CDV.h>
@interface ScreenOrientation : CDVPlugin
- (void) screenorientationFunction:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
@end
在ScreenOrientation输入以下。男,
在科尔多瓦项目点击搜索,然后搜索“shouldAutoRotate,找到下面和改变返回,在默认情况下这将是‘YES’将其更改为‘NO’。
CDVViewController。米
- (BOOL)shouldAutorotate
{
return NO;
}
而且在项目设置,在装置定向检查所有选项(不重要虽然),
Project Settings > Device orientation > Tick all 4 options.
,并在你的项目是这样称呼它,
callScreenOrientation('LandscapeLeft');
callScreenOrientation('LandscapeRight');
callScreenOrientation('Portrait');
callScreenOrientation('PortraitUpsideDown');
感谢您的支持!这是一个很大的帮助。我知道这个帖子是旧的,但我遇到了一些问题,我猜这是因为它的更新版本的Xcode/IOS等。我遇到的问题是代码工作正常后旋转屏幕对obj-c代码的语法更新很少,但是现在我遇到了一个问题,如果在执行代码时将shouldAutorotate设置为NO,它将不再有效。把它放回原处,它可以正常工作,但现在用户可以完全控制它何时旋转,这不是我想要的。你知道工作吗? –