简体   繁体   English

Xamarin.iOS:没有情节提要时启动屏幕后黑屏

[英]Xamarin.iOS: Black screen after launch screen when no storyboard

I don't want to use storyboard with my Xamarin.iOS app, so I did the following:我不想在我的 Xamarin.iOS 应用程序中使用故事板,因此我执行了以下操作:

1- Deleted the storyboard files. 1-删除了故事板文件。

2- Updated the plist.info file Application > Main Interface to have no value. 2- 更新了 plist.info 文件应用程序 > 主界面,使其没有价值。

3- Added the following code to the AppDelegate file. 3- 将以下代码添加到AppDelegate文件中。

[Export ("application:didFinishLaunchingWithOptions:")]
public bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
    // create a new window instance based on the screen size
    Window = new UIWindow(UIScreen.MainScreen.Bounds);

    var controller = new UIViewController();
    controller.View.BackgroundColor = UIColor.LightGray;
    controller.Title = "My Controller";

    var navController = new UINavigationController(controller);

    Window.RootViewController = navController;

    // make the window visible
    Window.MakeKeyAndVisible();

    return true;
}

But after doing this I received a black screen on the simulator after the launch screen finishes.但是在这样做之后,我在启动屏幕完成后在模拟器上收到了一个黑屏。 This happens even with brand new projects.即使是全新的项目也会发生这种情况。 I have uploaded a sample new project with these steps and issue here .我已上载这些步骤和问题的样本新的项目在这里

I am using Visual Studio 2019 - Xamarion.iOS 11.8.3 - XCode 11.3.我使用的是 Visual Studio 2019 - Xamarion.iOS 11.8.3 - XCode 11.3。

I was using Visual Studio 2015 in the recent past with no problem, and I think that this issue happened only with Visual Studio 2019. Unfortunately, currently I don't have a Visual Studio 2015 to experiment with.我最近使用 Visual Studio 2015 没有问题,我认为这个问题只发生在 Visual Studio 2019 上。不幸的是,目前我没有 Visual Studio 2015 可以试验。

Start from iOS 13, the SceneDelegate is responsible for setting up the scenes of your app, move your codes from AppDelegate to SceneDelegate :从 iOS 13 开始, SceneDelegate负责设置您的应用程序的场景,将您的代码从AppDelegate移动到SceneDelegate

[Export ("scene:willConnectToSession:options:")]
public void WillConnect (UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
{
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see UIApplicationDelegate `GetConfiguration` instead).

    UIWindowScene myScene = scene as UIWindowScene;
    Window = new UIWindow(myScene);

    UIViewController controller = new UIViewController();
    controller.View.BackgroundColor = UIColor.LightGray;
    controller.Title = "My Controller";

    UINavigationController navigationMain = new UINavigationController(controller);
    Window.RootViewController = navigationMain;
    Window.MakeKeyAndVisible();
}

Refer: Set rootViewController iOS 13 and The Scene Delegate In Xcode 11 And iOS 13参考: 在 Xcode 11 和 iOS 13 中设置 rootViewController iOS 13场景委托

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM