IOS Cordova 锁定启动画面方向
IOS Cordova Lock SplashScreen Orientation
背景
我正在使用 Cordova 将 javascript 部署到 iOS 设备。除此之外,我还使用 CDVSplashScreen 插件来显示我自己的启动画面。
我需要什么帮助
我希望能够锁定仅 Launch/Splash 屏幕,然后允许应用程序重新定向,因为它会针对所有其他视图进行调整。
我试过的
我已将以下内容添加到我的 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 中工作(但随后整个应用程序卡在纵向模式).
我的请求
有没有人以前使用过这个独特的插件集团,并且以前有过锁定 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 */
}
但我不确定设备是否正在触发事件。
谢谢大家的建议。我最终在 MainViewController 的以下函数中设置了方向:
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.acceptedOrientation = UIInterfaceOrientationMaskPortrait;
}
return self;
}
这对我来说似乎将 SplashScreen 锁定为纵向模式。
背景
我正在使用 Cordova 将 javascript 部署到 iOS 设备。除此之外,我还使用 CDVSplashScreen 插件来显示我自己的启动画面。
我需要什么帮助
我希望能够锁定仅 Launch/Splash 屏幕,然后允许应用程序重新定向,因为它会针对所有其他视图进行调整。
我试过的
我已将以下内容添加到我的 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 中工作(但随后整个应用程序卡在纵向模式).
我的请求
有没有人以前使用过这个独特的插件集团,并且以前有过锁定 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 */
}
但我不确定设备是否正在触发事件。
谢谢大家的建议。我最终在 MainViewController 的以下函数中设置了方向:
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.acceptedOrientation = UIInterfaceOrientationMaskPortrait;
}
return self;
}
这对我来说似乎将 SplashScreen 锁定为纵向模式。