简体   繁体   中英

IOS Cordova Lock SplashScreen Orientation

Background

I'm using Cordova to deploy javascript to iOS devices. Along with this, I'm using the CDVSplashScreen plugin in order to show my own splashscreen.

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:

<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:

-(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.

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).

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 -> General -> Deployment info)

  2. Put an event handler in your 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:

 @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:

- (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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