![](/img/trans.png)
[英]Ability to lock orientation of device with JavaScript in PhoneGap/Cordova
[英]IOS Cordova Lock SplashScreen Orientation
我正在使用Cordova將JavaScript部署到iOS設備。 與此同時,我正在使用CDVSplashScreen插件以顯示自己的啟動屏幕。
我希望能夠僅鎖定“啟動/啟動”屏幕,然后允許該應用程序重新定向,就像對所有其他視圖一樣。
我已將以下內容添加到我的config.xml文件中:
<preference name="SplashScreen" value="screen" />
<preference name="orientation" value="portrait" />
<preference name="SplashScreenDelay" value="1000000" />
我將以下代碼添加到CDVSplashScreen.m和CDVViewController + SplashScreen.m文件中:
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
我添加到config.xml文件中的內容似乎已將啟動屏幕鎖定為縱向模式...但是,在SplashScreen出現后,視圖將自由旋轉到橫向模式。
我不認為supportedInterfaceOrientations函數可以在任何地方做任何事情-它僅在mainViewController中起作用(但是整個應用程序都停留在Portrait模式下)。
以前有人使用過這種獨特的插件組合嗎? 您是如何解決的?
我尚未檢查,但是您可以嘗試以下操作:
根據需要鎖定Xcode中的方向。 (Xcode-> General->部署信息)
將事件處理程序放入您的javascript中:
window.addEventListener("orientationchange", function() { // Do some DOM-/CSS-manipulation depending on the value in window.orientation }, false);
@media screen and (orientation: portrait) { /* rotate your container */ } @media screen and (orientation: landscape) { /* rotate your container */ }
但是我不確定該設備是否正在觸發該事件。
謝謝你們的建議。 我最終在MainViewController的以下函數中設置了方向:
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.acceptedOrientation = UIInterfaceOrientationMaskPortrait;
}
return self;
}
這似乎將SplashScreen鎖定為縱向模式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.