简体   繁体   English

iOS Cordova Lock SplashScreen方向

[英]IOS Cordova Lock SplashScreen Orientation

Background 背景

I'm using Cordova to deploy javascript to iOS devices. 我正在使用Cordova将JavaScript部署到iOS设备。 Along with this, I'm using the CDVSplashScreen plugin in order to show my own splashscreen. 与此同时,我正在使用CDVSplashScreen插件以显示自己的启动屏幕。

What I need help with 我需要什么帮助

I want to be able to lock only the Launch/Splash Screens and then allow the app to reorient as it will for all other views. 我希望能够锁定“启动/启动”屏幕,然后允许该应用程序重新定向,就像对所有其他视图一样。

What I've tried 我尝试过的

I've added the following to my config.xml file: 我已将以下内容添加到我的config.xml文件中:

<preference name="SplashScreen" value="screen" />
<preference name="orientation" value="portrait" />
<preference name="SplashScreenDelay" value="1000000" />

And I added the following code to both the CDVSplashScreen.m and CDVViewController+SplashScreen.m files: 我将以下代码添加到CDVSplashScreen.mCDVViewController + SplashScreen.m文件中:

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

The Results: 结果:

What I've added to the config.xml file appears to have locked the Launch Screen in portrait mode...however, after the SplashScreen appears, the view will rotate freely to landscape mode. 我添加到config.xml文件中的内容似乎已将启动屏幕锁定为纵向模式...但是,在SplashScreen出现后,视图将自由旋转到横向模式。

I don't believe that the supportedInterfaceOrientations function is doing anything at all where it's at - it only works in the mainViewController (but then the entire app is stuck in Portrait mode). 我不认为supportedInterfaceOrientations函数可以在任何地方做任何事情-它仅在mainViewController中起作用(但是整个应用程序都停留在Portrait模式下)。

My Plea 我的请求

Has anyone used this unique conglomeration of plugins before with the same requirement of a locked SplashScreen before? 以前有人使用过这种独特的插件组合吗? How did you solve it? 您是如何解决的?

I haven't checked, but you could try the following: 我尚未检查,但是您可以尝试以下操作:

  1. Lock the orientation in Xcode to your needs. 根据需要锁定Xcode中的方向。 (Xcode -> General -> Deployment info) (Xcode-> General->部署信息)

  2. Put an event handler in your javascript: 将事件处理程序放入您的javascript中:

 window.addEventListener("orientationchange", function() { // Do some DOM-/CSS-manipulation depending on the value in window.orientation }, false); 

  1. Or you could use CSS to make changes: 或者,您可以使用CSS进行更改:

 @media screen and (orientation: portrait) { /* rotate your container */ } @media screen and (orientation: landscape) { /* rotate your container */ } 

But I'm not sure that the device is firing the event. 但是我不确定该设备是否正在触发该事件。

Thank you guys for your suggestions. 谢谢你们的建议。 I ended up setting the orientation in the following function in the MainViewController: 我最终在MainViewController的以下函数中设置了方向

- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
      self.acceptedOrientation = UIInterfaceOrientationMaskPortrait;
    }
  return self;
}

This seemed to lock the SplashScreen in portrait mode for me. 这似乎将SplashScreen锁定为纵向模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM