闪屏后黑屏。如何在我的应用程序启动时显示图像并稍后在特定时间将其删除?

Black screen after splash screen. How can I display an image when my application launches and remove it later at a certain point?

我想在用户启动我的应用程序时在整个屏幕上显示图像,因为在我的启动屏幕 (launchscreen.storyboard) 消失后黑屏持续 2 秒,直到 Draw(GameTime gameTime) 出现执行。在我执行 LogoView.RemoveFromSuperview() 之前需要显示图像;并且图像需要位于稍后将在 void Draw(GameTime gameTime) 中绘制的图像上方。

是否可以使用Assets.xcassets-->图片中的图片? iOS 会自动从 Assets.xcassets-->Image?

中为当前设备选择合适的图像尺寸吗?

Assets.xcassets image

我在 Whosebug 上找到了以下答案,但我不知道“视图”是什么。

如果我使用“查看”,我会在 Program.cs 中收到一条错误消息:

Error CS0103: The name 'View' does not exist in the current context

如何在我的应用程序启动时显示图像并稍后在 Game1.cs 的某个时间点将其删除?

Program.cs:

using System;
using Foundation;
using UIKit;

namespace MyProject
{
[Register("AppDelegate")]
class Program : UIApplicationDelegate
{
    private static Game1 game;
    private UIImageView LogoImage;

    public override void FinishedLaunching(UIApplication app)
    {
        global::Xamarin.Forms.Forms.Init();
        LogoImage = new UIImageView(UIImage.FromFile("Launchscreenlogo.png"));
        LogoImage.Tag = 1234;
        LogoImage.Frame = View.Frame;
        View.AddSubview(LogoImage);
        View.BringSubviewToFront(LogoImage);
        RunGame();
    }

    private void G_RemoveLogo(object sender, System.EventArgs e)
    {
        //remove image
        var LogoView = View.ViewWithTag(1234);
        if (null != LogoView)
            LogoView.RemoveFromSuperview();
    }
}
}

Game1.cs:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;

namespace MyProject
{
public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public event EventHandler RemoveLogo;

public Game1()
{
    _graphics = new GraphicsDeviceManager(this);
    Content.RootDirectory = "Content";
}

protected override void Initialize()
{
    base.Initialize();
}

protected override void LoadContent()
{
    _spriteBatch = new SpriteBatch(GraphicsDevice);
    // TODO: use this.Content to load your game content here

    RemoveLogo?.Invoke(this, new EventArgs());
}

protected override void Update(GameTime gameTime)
{
    base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);

    // TODO: Add your drawing code here

    base.Draw(gameTime);
}
}
}

View 属于 Controller ,我们可以在 ViewController 中轻松获得电流 View ,在 AppDelegate 中尝试使用 Window.RootViewController.View 代替。

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
   global::Xamarin.Forms.Forms.Init();
   LoadApplication(new App());

   LogoImage = new UIImageView(UIImage.FromFile("Launchscreenlogo.png"));
   LogoImage.Frame = UIScreen.MainScreen.Bounds;

   Window.RootViewController.View.AddSubview(LogoImage);
   Window.RootViewController.View.BringSubviewToFront(LogoImage);

   return base.FinishedLaunching(app, options);
}

public void G_RemoveLogo()
{
    //remove image
    LogoImage.RemoveFromSuperview();
}

并调用以下方法移除Game中的图片class。

(UIApplication.SharedApplication.Delegate as AppDelegate).G_RemoveLogo();