ionic解决启动白屏问题

ionic解决启动白屏问题

参考资料:

app启动后大概有几秒白屏,才会显示首页,下面介绍如何通过设置启动页来解决启动白屏问题:

config.xml配置

在cordova5.0版本以后,需要安装cordova-plugin-splashscreen插件以后才能修改和设置App的启动页面。

安装splashscreen插件:

cordova plugin add cordova-plugin-splashscreen
或
cordova plugin add https:
//github.com/apache/cordova-plugin-splashscreen.git

基本配置

然后在你的config.xml文件中,添加以下代码来设置APP的图标和启动页的图片:

<platform name="android">
<icon density="ldpi" src="res/icon/android/icon-36-ldpi.png" />
<icon density="mdpi" src="res/icon/android/icon-48-mdpi.png" />
<icon density="hdpi" src="res/icon/android/icon-72-hdpi.png" />
<icon density="xhdpi" src="res/icon/android/icon-96-xhdpi.png" />
<icon density="xxhdpi" src="res/icon/android/icon-144-xxhdpi.png" />
<icon density="xxxhdpi" src="res/icon/android/icon-192-xxxhdpi.png" />

<splash density="land-hdpi" src="res/screen/android/splash-land-hdpi.png" />
<splash density="land-ldpi" src="res/screen/android/splash-land-ldpi.png" />
<splash density="land-mdpi" src="res/screen/android/splash-land-mdpi.png" />
<splash density="land-xhdpi" src="res/screen/android/splash-land-xhdpi.png" />
<splash density="port-hdpi" src="res/screen/android/splash-port-hdpi.png" />
<splash density="port-ldpi" src="res/screen/android/splash-port-ldpi.png" />
<splash density="port-mdpi" src="res/screen/android/splash-port-mdpi.png" />
<splash density="port-xhdpi" src="res/screen/android/splash-port-xhdpi.png" />
</platform>
<platform name="ios">
<!-- iOS 8.0+ -->
<!-- iPhone 6 Plus -->
<icon src="res/icon/ios/icon-60@3x.png" width="180" height="180" />
<!-- iOS 7.0+ -->
<!-- iPhone / iPod Touch -->
<icon src="res/icon/ios/icon-60.png" width="60" height="60" />
<icon src="res/icon/ios/icon-60@2x.png" width="120" height="120" />
<!-- iPad -->
<icon src="res/icon/ios/icon-76.png" width="76" height="76" />
<icon src="res/icon/ios/icon-76@2x.png" width="152" height="152" />
<!-- iOS 6.1 -->
<!-- Spotlight Icon -->
<icon src="res/icon/ios/icon-40.png" width="40" height="40" />
<icon src="res/icon/ios/icon-40@2x.png" width="80" height="80" />
<!-- iPhone / iPod Touch -->
<icon src="res/icon/ios/icon.png" width="57" height="57" />
<icon src="res/icon/ios/icon@2x.png" width="114" height="114" />
<!-- iPad -->
<icon src="res/icon/ios/icon-72.png" width="72" height="72" />
<icon src="res/icon/ios/icon-72@2x.png" width="144" height="144" />
<!-- iPhone Spotlight and Settings Icon -->
<icon src="res/icon/ios/icon-small.png" width="29" height="29" />
<icon src="res/icon/ios/icon-small@2x.png" width="58" height="58" />
<icon src="res/icon/ios/icon-small@3x.png" width="87" height="87" />
<!-- iPad Spotlight and Settings Icon -->
<icon src="res/icon/ios/icon-50.png" width="50" height="50" />
<icon src="res/icon/ios/icon-50@2x.png" width="100" height="100" />


<splash src="res/screen/ios/Default~iphone.png" width="320" height="480"/>
<splash src="res/screen/ios/Default@2x~iphone.png" width="640" height="960"/>
<splash src="res/screen/ios/Default-Portrait~ipad.png" width="768" height="1024"/>
<splash src="res/screen/ios/Default-Portrait@2x~ipad.png" width="1536" height="2048"/>
<splash src="res/screen/ios/Default-Landscape~ipad.png" width="1024" height="768"/>
<splash src="res/screen/ios/Default-Landscape@2x~ipad.png" width="2048" height="1536"/>
<splash src="res/screen/ios/Default-568h@2x~iphone.png" width="640" height="1136"/>
<splash src="res/screen/ios/Default-667h.png" width="750" height="1334"/>
<splash src="res/screen/ios/Default-736h.png" width="1242" height="2208"/>
<splash src="res/screen/ios/Default-Landscape-736h.png" width="2208" height="1242"/>
</platform>

其他配置

<preference name="SplashScreen" value="screen"/>
<!--禁止启动时出现转圈 -->
<preference name="ShowSplashScreenSpinner" value="false" />
<!--在Android平台下的特殊设置,每次打开APP都显示启动页-->
<preference name="SplashShowOnlyFirstTime" value="false"/>
<!--设置启动页不自动消失,原先默认值为true-->
<preference name="AutoHideSplashScreen" value="false" />
<!--设置显示启动页时间为30秒,默认为3秒。若想禁用启动页,则设置value为0。如果是iOS平台上想禁止启动页面,还需要添加<preference name="FadeSplashScreenDuration" value="0"/>-->
<preference name="SplashScreenDelay" value="30000"/>
<!--设置启动页直接消失,默认值为true-->
<preference name="FadeSplashScreen" value="false" />

若要使用启动页面淡入淡出的效果,则还需添加如下配置:

<!--设置启动页逐渐消失-->
<preference name="FadeSplashScreen" value="true" />
<!--设置启动页逐渐消失的时间,默认为500。注意:FadeSplashScreenDuration时间是包含在SplashScreenDelay的时间里的。-->
<!--在Android平台下的特殊设置,默认为false。当设置为true时,则不会拉伸图片来填充屏幕,会以图片原始比例显示图片。-->
<preference name="SplashMaintainAspectRatio" value="true"/>
<preference name="FadeSplashScreenDuration" value="500" />

隐藏启动页

splashscreen插件提供有以下两个方法:

navigator.splashscreen.hide();//隐藏启动页面

navigator.splashscreen.show();//显示启动页面

你可以在$ionicPlatform.ready中调用上面的hide方法,也可以引入$cordovaSplashScreen,然后使用$cordovaSplashScreen.hide()隐藏启动页。如果是ionic2则采用如下方式:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值