仅在从iPhone 11开始使用故事板启动后,应用程序启动时出现黑屏

问题描述 投票:1回答:1

如果我不使用启动屏幕情节提要,该应用程序将在iPhone 11 / iPhone XS Max等设备上运行,尽管我使用了信箱,但我不希望这样做。

当我使用启动屏幕情节提要板时,会显示启动屏幕,然后屏幕变黑。这是它使用的代码的一部分。

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Init the window
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
        [CCDirector setDirectorType:kCCDirectorTypeDefault];

    CCDirector *director = [CCDirector sharedDirector];

    // Init the View Controller
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;
       // Set RootViewController to window
       self.window.rootViewController = viewController;
    EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
                                   pixelFormat:kEAGLColorFormatRGB565   // kEAGLColorFormatRGBA8
                                   depthFormat:0                        // GL_DEPTH_COMPONENT16_OES
                        ];

    // attach the openglView to the director
    [director setOpenGLView:glView];

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        //  // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
        if( ! [director enableRetinaDisplay:YES] )
            CCLOG(@"Retina Display Not supported");

    }

#if GAME_AUTOROTATION == kGameAutorotationUIViewController
    [director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif

    [director setAnimationInterval:1.0/60];
    // make the OpenGLView a child of the view controller
    [viewController setView:glView];
    // make the View Controller a child of the main window
    [window addSubview: viewController.view];
    [window makeKeyAndVisible];

    // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
    // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
    // You can change anytime.
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
    // Removes the startup flicker
    [self removeStartupFlicker];
    self.window.rootViewController = self.viewController;
    // Run the intro Scene
    [[CCDirector sharedDirector] runWithScene: [MainMenuScene scene]];


    return YES;
}
ios objective-c cocos2d-iphone iphone11
1个回答
0
投票

您可能正在iPhone 11上运行iOS 13?如果在装有iOS 12或更早版本的设备上运行应用程序,则只需设置主窗口和rootViewController。在iOS 13中,请勿设置主窗口和rootViewController。

您应该在运行时进行检查。类似于:

if (@available(iOS 13, *)) {
    // don't set up main window and rootViewController

} else {  // iOS 12 and below

    // Init the window
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Init the View Controller
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;

    // Set RootViewController to window
    self.window.rootViewController = viewController;

}

但是,为什么它以前在iPhone 11上运行? (当您不使用启动屏幕情节提要板,并且它在信箱模式下运行时)。我怀疑这是因为,如果没有启动屏幕情节提要,它就以兼容模式运行,因此不使用iOS 13 sdk。在您添加了启动屏幕故事板之后,它就使用了iOS 13 sdk,因此您不应设置主窗口和rootViewController。

© www.soinside.com 2019 - 2024. All rights reserved.