ios - 仅在 iPhone 11 及更高版本上使用 Storyboard启动后应用程序启动黑屏

标签 ios objective-c cocos2d-iphone iphone11

如果我不使用启动屏幕 Storyboard,该应用程序将在 iPhone 11/iPhone XS Max 等设备上运行,尽管是黑框,这是我不想要的。

当我使用启动屏幕 Storyboard时,启动屏幕显示,然后屏幕变黑。这是它使用的代码的一部分。

 - (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;
}

最佳答案

您可能在 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 上运行? (当您没有使用启动屏幕 Storyboard,并且它以信箱模式运行时)。我怀疑这是因为没有启动屏幕 Storyboard,它在兼容模式下运行,所以没有使用 iOS 13 sdk。添加启动屏幕 Storyboard后,它使用的是 iOS 13 SDK,您不应该设置主窗口和 rootViewController。

关于ios - 仅在 iPhone 11 及更高版本上使用 Storyboard启动后应用程序启动黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61486454/

相关文章:

ios - 我如何知道 Objective-C 代码是否正在 iOS 模拟器中运行?

ios - iOS 11 中的 Photopicker 和 FB GrapSharer 问题

ios - 使用 reloadData 时如何执行单元格选择动画?

cocos2d-iphone - Cocos2d : Move a Sprite along a path/bezier?

iphone - 在非 cocos2d 项目中包含 cocos2d

ios - 对于 iOS 和 Xcode,我们可以为 UIImageView 对象创建一个 Action 吗?

ios - 如何在 iOS 中设置自定义日期格式?

iphone - 在objective-c中直接在后台发送电子邮件

cocos2d-iphone - 更改 Sprite 使用的 png

ios - 协议(protocol)方法/函数中的 Swift 默认参数和忽略参数