【问题标题】:Xamarin.iOS: Black screen after launch screen when no storyboardXamarin.iOS:没有故事板时启动屏幕后黑屏
【发布时间】:2020-01-12 08:43:12
【问题描述】:

我不想将情节提要与我的 Xamarin.iOS 应用程序一起使用,因此我执行了以下操作:

1- 删除了故事板文件。

2- 更新了 plist.info 文件 Application > Main Interface 使其没有任何价值。

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

但是这样做之后,启动屏幕完成后,我在模拟器上收到了黑屏。即使是全新的项目也会发生这种情况。我已经上传了一个包含这些步骤的示例新项目并发出here

我正在使用 Visual Studio 2019 - Xamarion.iOS 11.8.3 - XCode 11.3。

我最近使用 Visual Studio 2015 没有问题,我认为这个问题只发生在 Visual Studio 2019 中。不幸的是,目前我没有 Visual Studio 2015试验一下。

【问题讨论】:

    标签: c# ios xamarin


    【解决方案1】:

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

    参考:Set rootViewController iOS 13The Scene Delegate In Xcode 11 And iOS 13

    【讨论】:

      猜你喜欢
      • 2018-11-27
      • 1970-01-01
      • 1970-01-01
      • 2014-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-08
      相关资源
      最近更新 更多