2

所以,我的 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 语句中触发,除了我真的可以使用你们的帮助来确定我需要进行哪些更改。

4

2 回答 2

1

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

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

或者

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
于 2012-09-26T17:20:40.757 回答
1

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

于 2012-09-26T21:12:42.997 回答