ionic 2/3 : 为应用程序创建一个起始页
ionic 2/3 : Create a starting page for application
我想创建一个显示徽标并在显示应用程序内容之前显示 2 秒的起始页,有人可以告诉我正确的方法吗?谢谢!
使用原生离子闪屏组件:
您所要做的就是创建一个新页面,该页面将在应用程序启动时显示,您将在该页面内执行应用程序开始运行所需的相关代码。
因为我不知道您是否在使用延迟加载的页面,所以我会将页面创建留到您可以完全使用该页面的程度。
因此,在您的 CLI 中使用 ionic g page yourPage
创建一个新页面
在您的 app.components.ts
中,您将首先指向创建的页面
app.components.ts:
export class MyApp {
rootPage: any = 'YourPage'; // YOUR PAGE WILL BE THE ROOT PAGE FOR NOW
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
});
}
}
在您创建的页面中,您将执行以下操作:
yourPage.ts:
constructor(public navCtrl: NavController){}
// USING A LIFECYCLE HOOK TO EXECUTE CODE AFTER THE PAGE IS FULLY LOADED
ionViewDidLoad(){
setTimeout(()=> {
// YOU'LL SET THE ROOT WITH THE HOME PAGE YOU NEED TO SHOW AFTER YOU START. DON'T PUSH THE PAGE SINCE YOU DON'T NEED THE USER TO NAVIGATE BACK TO IT.
// You can also do other relevant code here, like check if the user is logged or not before seting the root to the right page.
this.navCtrl.setRoot('YourMainHomePage');
}, 2000)
}
在您的页面 html 代码中,您将只有图像:
yourPage.html
<!-- REMOVE HEADER -->
<ion-content padding>
<img src="path/to/image" alt="my company" />
</ion-content>
希望对您有所帮助
我想创建一个显示徽标并在显示应用程序内容之前显示 2 秒的起始页,有人可以告诉我正确的方法吗?谢谢!
使用原生离子闪屏组件:
您所要做的就是创建一个新页面,该页面将在应用程序启动时显示,您将在该页面内执行应用程序开始运行所需的相关代码。
因为我不知道您是否在使用延迟加载的页面,所以我会将页面创建留到您可以完全使用该页面的程度。
因此,在您的 CLI 中使用 ionic g page yourPage
在您的 app.components.ts
中,您将首先指向创建的页面
app.components.ts:
export class MyApp {
rootPage: any = 'YourPage'; // YOUR PAGE WILL BE THE ROOT PAGE FOR NOW
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
});
}
}
在您创建的页面中,您将执行以下操作:
yourPage.ts:
constructor(public navCtrl: NavController){}
// USING A LIFECYCLE HOOK TO EXECUTE CODE AFTER THE PAGE IS FULLY LOADED
ionViewDidLoad(){
setTimeout(()=> {
// YOU'LL SET THE ROOT WITH THE HOME PAGE YOU NEED TO SHOW AFTER YOU START. DON'T PUSH THE PAGE SINCE YOU DON'T NEED THE USER TO NAVIGATE BACK TO IT.
// You can also do other relevant code here, like check if the user is logged or not before seting the root to the right page.
this.navCtrl.setRoot('YourMainHomePage');
}, 2000)
}
在您的页面 html 代码中,您将只有图像:
yourPage.html
<!-- REMOVE HEADER -->
<ion-content padding>
<img src="path/to/image" alt="my company" />
</ion-content>
希望对您有所帮助