egret-docs-master/microclient/manual/launchimage/README.md

2.4 KiB
Raw Permalink Blame History

在微端中使用启动图

在应用启动之前,为了解决白屏体验不好的问题,一般会先显示一张图片,等应用启动后再关掉这个图片。微端中也有这个方法。

安卓示例demo下载地址

iOS示例demo下载地址

启动图的意义

启动图可以减少用户看到的黑屏、白屏或者花屏的可能性,是 APP 的启动流程更加的自然,给用户带来更好的体验。

安卓启动图的使用方法

通过 NativeLauncher 类的 initViews 方法启用启动图功能,函数原型如下:

public void initViews(FrameLayout layout, int imageResId, int duration);

其中layout 表示 View 的根节点imageResId 表示启动图的图片资源 idduration 表示启动图展示的时间,单位为毫秒。如果该时间等于 0则表示启动图启动图会在游戏启动后自行关闭如果大于 0则表示启动图会在到达该时间之后关闭。

举例来说,假设 res 文件夹下面的 drawable 目录下有一个名为 background.jpg 的图片,该图片被用于启动图并且启动图的展示时间为 2 秒,那么示例代码如下:

launcher.initViews(rootLayout, R.drawable.background, 2000);

其中launcher 来自于 NativeLauncher 类rootLayout 是 View 的根节点R.drawable.background 指向前面的 background.jpg 图片2000 表示展示时间为 2 秒。

iOS启动图的使用方法

通过NativeLauncher类的setLaunchScreenImagePathAndDuration方法启用启动页功能函数原型如下

- (void)setLaunchScreenImagePathAndDuration:(NSString*)imagePath Duration:(int)duration;

其中imagePath表示启动页的图片资源路径duration表示启动页展示的时间单位为毫秒。如果该时间等于0则表示启动页会在游戏启动后自行关闭如果大于0则表示启动页会在到达该时间之后关闭。

举例来说假设程序中有一个名为background.jpg的图片该图片被用于启动页并且启动页的展示时间为2秒那么示例代码如下

[super.launcher setLaunchScreenImagePathAndDuration:@"background.jpg" Duration:2000];

其中launcher来自于NativeViewController类@"background.jpg"指向前面的background.jpg图片2000表示展示时间为2秒。