繁体   English   中英

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

[英]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-->Image 中的图像? iOS 会自动从 Assets.xcassets-->Image 中为当前设备选择合适的图像尺寸吗?

Assets.xcassets 图片

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

iOS 使图像适合屏幕

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

错误 CS0103:当前上下文中不存在名称“视图”

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

程序.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();
    }
}
}

游戏1.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();
}

并调用以下方法移除游戏 class 中的图像。

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

暂无
暂无

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

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