2012-09-26 48 views
2

所以,我有我的AppDelegate.m此功能:闪屏问题,Xcode中/ iOS 6中/ PhoneGap的

- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions 
{   
    [CDVLocalStorage __verifyAndFixDatabaseLocations]; 
    NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey]; 
    if (url && [url isKindOfClass:[NSURL class]]) { 
     invokeString = [url absoluteString]; 
     NSLog(@"PHR launchOptions = %@", url); 
    } 
    CGRect screenBounds = [[UIScreen mainScreen] bounds]; 
    self.window = [[UIWindow alloc] initWithFrame:screenBounds]; 
    self.window.autoresizesSubviews = YES; 
    self.detailViewController 
    self.detailViewController = [[MainViewController alloc] init]; 
    self.detailViewController.useSplashScreen = YES; 
    self.detailViewController.wwwFolderName = @"www"; 
    self.detailViewController.startPage = @"index.html"; 
    self.detailViewController.invokeString = invokeString; 
    NSString *deviceType = [UIDevice currentDevice].model; 

    if (![deviceType hasPrefix:@"iPad"] && ![deviceType hasPrefix:@"iPad Simulator"]) 
    { 
     CGRect viewBounds = [[UIScreen mainScreen] applicationFrame]; 
     detailViewController.view.frame = viewBounds; 

     BOOL forceStartupRotation = YES; 
     UIDeviceOrientation curDevOrientation = [[UIDevice currentDevice] orientation]; 

     if (UIDeviceOrientationUnknown == curDevOrientation) { 
      curDevOrientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation]; 
     } 

     if (UIDeviceOrientationIsValidInterfaceOrientation(curDevOrientation)) { 
       if ([self.detailViewController supportsOrientation:curDevOrientation]) { 
        forceStartupRotation = NO; 
       } 
     } 

     if (forceStartupRotation) { 
      UIInterfaceOrientation newOrient; 
      if ([self.detailViewController supportsOrientation:UIInterfaceOrientationPortrait]) 
       newOrient = UIInterfaceOrientationPortrait; 
      else if ([self.detailViewController supportsOrientation:UIInterfaceOrientationLandscapeLeft]) 
       newOrient = UIInterfaceOrientationLandscapeLeft; 
      else if ([self.detailViewController supportsOrientation:UIInterfaceOrientationLandscapeRight]) 
       newOrient = UIInterfaceOrientationLandscapeRight; 
      else 
       newOrient = UIInterfaceOrientationPortraitUpsideDown; 

      NSLog(@"AppDelegate forcing status bar to: %d from: %d", newOrient, curDevOrientation); 
      [[UIApplication sharedApplication] setStatusBarOrientation:newOrient]; 
     } 

     self.window.rootViewController = self.detailViewController; 
    } else { 
     NavViewController *leftViewController = [[NavViewController alloc] initWithNibName:@"NavViewController" bundle:nil]; 
     UINavigationController *leftNavViewController = [[UINavigationController alloc] initWithRootViewController:leftViewController]; 
     leftNavViewController.navigationBarHidden = YES; 

     UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController]; 
     detailNavigationController.navigationBarHidden = YES; 

     leftViewController.detailViewController = detailViewController; 

     self.splitViewController = [[UISplitViewController alloc] init]; 
     self.splitViewController.viewControllers = [NSArray arrayWithObjects:leftNavViewController, detailNavigationController, nil]; 

     self.window.rootViewController = self.splitViewController; 
     self.splitViewController.delegate = detailViewController; 
     detailViewController.svc = self.splitViewController; 
    } 
    [self.window makeKeyAndVisible]; 

    return YES; 
} 

是的,我知道这是一个很大的代码,但我完全不能确定的是什么因为在这个函数里面,我不知道什么是错误的。

本质上,我的应用在横向模式下加载ipad,但启动屏幕旋转90度并显示纵向而不是横向,然后闪回我的实际启动画面。从代码中可以看出,它是在设备检查的else语句中触发的,除此之外,我可以真正使用你们的帮助来确定我需要做出什么改变。

+0

+1这个不错的问题 –

回答

1

所以,我终于得到这个解决。在“showSplashScreen”函数中,在Cordova文件中的CDVViewController.m中(您必须拥有2.0.0才能获得源代码),因此您必须在所有if检查中注释掉startupImageTransform = CGAffineTransformMakeRotation(degreesToRadian(90));行,因为该设备会为你,然后phonegap尝试重新定位它。

1

如果您只在应用程序中使用横向模式,请将setStatusBarOrientation设置为横向模式。

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight]; 

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft]; 
+0

我只需要iPad上的所有4个接口,只有iPod和iPhone的肖像。方向工作正常,它们启动并且可以在所有方向上交互,只是闪屏旋转错误,并且是唯一支持我iOS 6兼容更新的东西。 –

+0

请加''[[UIApplication sharedApplication] setStatusBarOrientation:curDevOrientation];''forceStartupRotation = NO之后'' –

+0

不行。我将它添加到非Ipad部分以及iPad部分,并且一旦xcode连接,它仍会旋转闪屏。它显示正确的飞溅,xcode连接,并显示旋转(肖像)飞溅,然后它进入我的加载屏幕。 –