背景
我正在使用 Cordova 将 javascript 部署到 iOS 设备。除此之外,我还使用 CDVSplashScreen 插件来显示我自己的闪屏。
我需要什么帮助
我希望能够仅锁定启动/启动屏幕,然后允许应用重新定向,就像它对所有其他 View 一样。
我尝试过的
我已将以下内容添加到我的 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 文件中添加的内容似乎已将 Launch Screen 锁定为纵向模式...但是,在 SplashScreen 出现时, View 将自由旋转到横向模式。
我不相信 supportedInterfaceOrientations 函数在它所在的位置做任何事情 - 它只在 mainViewController 中工作(但随后整个应用程序卡在纵向模式)。
我的请求
以前有没有人使用过这种独特的插件组合,并且之前有过锁定 SplashScreen 的相同要求?你是怎么解决的?
最佳答案
我还没有检查过,但你可以尝试以下方法:
根据您的需要在 Xcode 中锁定方向。 (Xcode -> 常规 -> 部署信息)
在您的 javascript 中放置一个事件处理程序:
window.addEventListener("orientationchange", function() {
// Do some DOM-/CSS-manipulation depending on the value in window.orientation
}, false);
- 或者您可以使用 CSS 进行更改:
@media screen and (orientation: portrait) {
/* rotate your container */
}
@media screen and (orientation: landscape) {
/* rotate your container */
}
但我不确定设备是否正在触发事件。
关于android - IOS Cordova 锁定启动画面方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33745799/