objective-c - 闪屏问题,Xcode/iOS 6/Phonegap

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

最佳答案

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

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];

关于objective-c - 闪屏问题,Xcode/iOS 6/Phonegap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12606978/

相关文章:

ios - “CGPathGetBoundingBox”已被属性 'CGPath.boundingBox' 取代

ios - Storyboard:如何在更改布局约束时让 Xcode 自动更新框架?

iphone - 如何从 Xcode 项目中清理过时和排除的文件?

iphone - 检查 modalViewController 的动画是否完成

iphone - 如何创建可变的 CGImageRefs 数组?

iphone - 在没有分发文件的情况下将 ipa 发送给测试人员(仅带有配置文件)

iphone - 无法在应用内取消 NSLocalNotification 和调用 NSLocalNotification

ios - 所有 cocoa pod 库中的 Xcode 7.3.1 错误太突然了

iphone - 应用程序设计和 AppDelegate

ios - 文本渲染 iOS - 渲染快速变化的文本的最高效方式