ionic 2/3 : 用LocalStorage控制splashScreen的开启
ionic 2/3 : control the opening of splashScreen with LocalStorage
打开启动画面时如何设置 localStorage 值并测试 localstorage 值以不再打开启动画面,我使用的是 ionic 3,我在 config.xml 上设置了此配置:
<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="FadeSplashScreenDuration" value="300" />
<preference name="SplashShowOnlyFirstTime" value="true" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="0" />
<preference name="ShowSplashScreen" value="false" />
这是我在 home.ts 文件中的 ionviewdidload 函数:
ionViewDidLoad(){
if (localStorage.getItem('splash')=='0') {
this.tabBarElemen.style.display = 'none'
setTimeout(() => {
this.splash = false;
localStorage.setItem('splash','1');
this.tabBarElemen.style.display = 'flex';
}, 2000);
}
}
这里是启动画面的 html 代码:
<div id="custom-overlay" [style.display]="splash ? 'flex': 'none'">
<div class="flb">
<div class="Aligner-item Aligner-item--top"></div>
<img class="splash-screen-logo" src="img/logo.svg">
<div class="Aligner-item Aligner-item-bottom"></div>
</div>
</div>
请帮忙!谢谢
使用 Ionic Native 的启动画面插件,您可以完全控制 showing/hiding 您的启动画面。
示例:
import { SplashScreen } from '@ionic-native/splash-screen';
constructor(private splashScreen: SplashScreen) { }
this.splashScreen.show();
this.splashScreen.hide();
可以在以下位置找到更多信息:Splashscreen docs
打开启动画面时如何设置 localStorage 值并测试 localstorage 值以不再打开启动画面,我使用的是 ionic 3,我在 config.xml 上设置了此配置:
<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="FadeSplashScreenDuration" value="300" />
<preference name="SplashShowOnlyFirstTime" value="true" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="0" />
<preference name="ShowSplashScreen" value="false" />
这是我在 home.ts 文件中的 ionviewdidload 函数:
ionViewDidLoad(){
if (localStorage.getItem('splash')=='0') {
this.tabBarElemen.style.display = 'none'
setTimeout(() => {
this.splash = false;
localStorage.setItem('splash','1');
this.tabBarElemen.style.display = 'flex';
}, 2000);
}
}
这里是启动画面的 html 代码:
<div id="custom-overlay" [style.display]="splash ? 'flex': 'none'">
<div class="flb">
<div class="Aligner-item Aligner-item--top"></div>
<img class="splash-screen-logo" src="img/logo.svg">
<div class="Aligner-item Aligner-item-bottom"></div>
</div>
</div>
请帮忙!谢谢
使用 Ionic Native 的启动画面插件,您可以完全控制 showing/hiding 您的启动画面。
示例:
import { SplashScreen } from '@ionic-native/splash-screen';
constructor(private splashScreen: SplashScreen) { }
this.splashScreen.show();
this.splashScreen.hide();
可以在以下位置找到更多信息:Splashscreen docs