2012-06-12 27 views
11

我試圖做一個landscape only app,但我根本無法產生任何旋轉。爲什麼當設備旋轉時,我的Cordova/PhoneGap iOS應用程序不會旋轉?

以前有autorotate設置PhoneGap.plist但在phonegap 1.8.0我可以找到它。它還存在嗎?

還有什麼可能是錯誤的,我的應用程序不旋轉?

UPDATE

我知道有一個包含只有一個字 「測試」 網頁。我只將目標設備設置爲iPad,並啓用了所有四個方向。還有什麼可能是錯的?

是否需要有特殊的html文檔類型?我需要包含一些cordova-1.8.0.js嗎?我無法找到一個iOS(!?!),所以我測試了它的Android版本。我讀的API現在是相同的,所以我可以使用android .js文件?

回答

11

PiTheNumber的答案尋找那些細跟修改科爾多瓦生成的本機代碼確定。

this JIRA issue在科爾多瓦,並且整齊地解釋in this blog,你也可以使用的plist值或在你的JavaScript代碼,這很適合我很好定義window.shouldRotateToOrientation功能

window.shouldRotateToOrientation = function(degrees) { 
return true; 
} 

(如果它是「一個頁面的應用程序」,因爲大多數應用程序科爾多瓦是如此,爲您的整個應用程序),這將使當前頁面的設備方向。請注意,您也可以根據以度爲單位的旋轉值啓用它,或者甚至爲什麼不啓用它,只能在某些視圖中啓用它,或者讓用戶在您的HTML應用程序中進行選擇...很好,是不是。爲了記錄,我不需要做任何事情來獲得iOS 8 iPad手柄的旋轉,而iOS 6和iOS 7 iPhone在默認情況下不會在當前的Cordova版本(4.2.0, cordova ios平臺版本「ios 3.7.0」)。這是因爲可以在Xcode上爲每個「設備類型」(平板電腦/手機)授予不同的輪換設置。需要注意的是Cordova將首先檢查上面的JS函數是否存在,然後如果該函數不存在或者它不允許旋轉,那麼將使用Xcode旋轉設置。

+0

你是一個救星! – MrCujo

8

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

Source

+0

這個固定爲我。 (對於我來說,使用默認的PhoneGap項目,旋轉在iPad上工作,但不在iPhone上)。 – mpontillo

7

您可以添加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> 

爲iPad:

<key>UISupportedInterfaceOrientations~ipad</key> 
    <array> 
     <string>UIInterfaceOrientationPortrait</string> 
     <string>UIInterfaceOrientationLandscapeLeft</string> 
     <string>UIInterfaceOrientationPortraitUpsideDown</string> 
     <string>UIInterfaceOrientationLandscapeRight</string> 
    </array> 
+0

這個現代更​​新解決了我的問題。 – nokturnal

+0

我在別人面前試過這個。第一次像魅力一樣工作。沒有麻煩。謝謝!這應該是選擇的答案!太乾淨了! – moeiscool

15

我嘗試了上述JavaScript解決方案,並沒有得到快樂 在Visual Studio 2015年我將config.xml更改爲

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

Cordova 5 build command is deleting iOS device orientation settings

採取我並不需要的JavaScript只是配置設置

+0

不幸的是,現在在科爾多瓦5.4中被破壞:https://issues.apache.org/jira/browse/CB-9975 – user206481

+0

@ user206481我使用的是5.4.1,它工作正常 – RezaRahmati

+0

** name =「orientation」**沒有工作,** name =「Orientation」**(介意BIG O)似乎是正確的 – shershen

相關問題