启动画面问题,Xcode / iOS 6 / Phonegap

时间:2012-09-26 17:12:26

标签: objective-c ios xcode cordova

所以,我在AppDelegate.m中有这个功能:

- (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语句中触发,除此之外,我可以真正利用你们的帮助来弄清楚我需要做出哪些改变。

2 个答案:

答案 0 :(得分:1)

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

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];

答案 1 :(得分:1)

所以,我最终成功地解决了这个问题。在Cordova文件中的CDVViewController.m(你必须有2.0.0来获取源代码)在" showSplashScreen"函数你必须在所有if检查中注释掉行startupImageTransform = CGAffineTransformMakeRotation(degreesToRadian(90));,因为设备为你做旋转,然后phonegap尝试重新定位它。