为什么';当设备旋转时,我的Cordova/PhoneGap iOS应用程序是否旋转?

为什么';当设备旋转时,我的Cordova/PhoneGap iOS应用程序是否旋转?,ios,cordova,screen-orientation,Ios,Cordova,Screen Orientation,我试着做一个旋转,但我根本不能产生任何旋转 以前在PhoneGap.plist中有一个autorotate设置,但在PhoneGap 1.8.0中我可以找到它。它还存在吗 如果我的应用程序没有旋转,还有什么问题吗 更新 我知道有一个网页只包含一个词“测试”。我只将目标设备设置为iPad,并启用了所有四个方向。还有什么问题 是否需要特殊的html文档类型?我需要包括一些cordova-1.8.0.js吗?我找不到iOS(!?!)版本,所以我用android版本测试了它。我读到API现在是一样的,所

我试着做一个旋转,但我根本不能产生任何旋转

以前在
PhoneGap.plist中有一个
autorotate
设置,但在PhoneGap 1.8.0中我可以找到它。它还存在吗

如果我的应用程序没有旋转,还有什么问题吗

更新

我知道有一个网页只包含一个词“测试”。我只将目标设备设置为iPad,并启用了所有四个方向。还有什么问题


是否需要特殊的html文档类型?我需要包括一些cordova-1.8.0.js吗?我找不到iOS(!?!)版本,所以我用android版本测试了它。我读到API现在是一样的,所以我可以使用android.js文件吗?

Classes/MainViewController.m
返回true:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    return true;
}
对于iOS>=6

- (BOOL)shouldAutorotate {
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

对于那些对修改Cordova生成的本机代码很在行的人来说,PiTheNumber的答案看起来不错

在Cordova之后,正如清楚地解释的,您还可以在Javascript代码中使用plist值或定义window.shouldRotateToOrientation函数,这非常适合我

window.shouldRotateToOrientation = function(degrees) {
 return true;
}
这将为当前页面启用设备定位(因此,如果您的整个应用程序与大多数Cordova应用程序一样是“一页应用程序”,则为其启用设备定位)。注意:你也可以根据旋转角度值来决定启用它,或者,为什么不,只在某些视图上启用它,或者让用户在你的HTML应用程序中选择。。。很好,不是吗


作为记录,我不需要做任何事情来实现iOS 8 iPad手柄的旋转,而iOS 6和iOS 7 iPhone在当前Cordova版本(4.2.0,Cordova iOS平台版本“iOS 3.7.0”)中默认情况下都不会处理。这是因为可以在Xcode上为每个“设备类型”(平板电脑/手机)授予不同的旋转设置。需要注意的是,Cordova将首先检查上面的JS函数是否存在,然后如果该函数不存在或不允许旋转,将使用Xcode旋转设置。

您可以添加UISupportedInterfaceOrientations

platroms/ios/{ProjectName}/{ProjectName-info.plist

添加以下行:

对于Iphone:

<key>UISupportedInterfaceOrientations</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationLandscapeLeft</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
UI支持接口方向
UIInterfaceOrientationPortrait
UIInterface方向和左视图
UIInterfaceOrientation上下方向图
UIInterfaceOrientationAndscapeRight
对于Ipad:

<key>UISupportedInterfaceOrientations~ipad</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationLandscapeLeft</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
ui支持的界面方向~ipad
UIInterfaceOrientationPortrait
UIInterface方向和左视图
UIInterfaceOrientation上下方向图
UIInterfaceOrientationAndscapeRight

我尝试了上面的JavaScript解决方案,但没有得到任何乐趣 在Visual Studio 2015中,我将config.xml更改为

<preference name="orientation" value="all" />

取自


我不需要javascript,只需要配置设置就可以了。(对我来说,默认的PhoneGap项目中,rotation在iPad上工作,但在iPhone上不起作用。)不幸的是,cordova 5.4中出现了这种情况:name=“orientation”不起作用,name=“orientation”(注意大O)似乎正确。我在其他人之前试过这个。第一次很有魅力。不麻烦。谢谢!这应该是选择的答案!!!太干净了!!!