ToB企服应用市场:ToB评测及商务社交产业平台

标题: 纯血鸿蒙APP开辟实战—启动页面 [打印本页]

作者: 金歌    时间: 2024-8-21 11:41
标题: 纯血鸿蒙APP开辟实战—启动页面
启动页面整体结果如下:

1,结构代码,头部一个logo 使用Image ,底部一个名称图片使用Image,末了一个描述是一个文本Text 组成
代码如下:
  1. Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center}){
  2. Column() {
  3. Image($r('app.media.ic_eshop'))
  4. .width(100)
  5. .aspectRatio(1)
  6. .objectFit(ImageFit.Contain)
  7. }
  8. .justifyContent(FlexAlign.Center)
  9. .alignItems(HorizontalAlign.Center)
  10. .flexGrow(1)
  11. Image($r('app.media.ic_title'))
  12. .width($r('app.float.text_image_width'))
  13. .height($r('app.float.text_image_height'))
  14. .objectFit(ImageFit.Contain)
  15. Text($r('app.string.splash_desc'))
  16. .fontColor('#66000000')
  17. .fontSize($r('app.float.bigger_font_size'))
  18. .letterSpacing(16)
  19. .margin({ top: $r('app.float.vp_twelve'), bottom: $r('app.float.splash_text_margin_bottom') })
  20. }
  21. .height('100%')
  22. .width('100%')
  23. .backgroundColor('#f1f3f5')
复制代码
2,启动页进入下一页是自动进入,需要在aboutToAppear添加一个定时器,通过定时器定点时间做跳转,通过设置路由进入下一页 router.replaceUrl({ url: 'pages/MainPage' })
  1. aboutToAppear() {
  2.   this.timeOutId = setTimeout(() => {
  3.   router.replaceUrl({ url: 'pages/MainPage' })
  4.   .catch((err: Error) => {
  5.     console.error(JSON.stringify(err));
  6.   })
  7.   }, 2000);
  8. }
复制代码
3,烧毁定时器,在aboutToDisappear中烧毁定时器
  1. aboutToDisappear() {
  2.   clearTimeout(this.timeOutId);
  3. }
复制代码
4,完整代码如下
  1. import router from '@ohos.router';@Entry@Componentstruct Index {private timeOutId: number = 0;build() {
  2. Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center}){
  3. Column() {
  4. Image($r('app.media.ic_eshop'))
  5. .width(100)
  6. .aspectRatio(1)
  7. .objectFit(ImageFit.Contain)
  8. }
  9. .justifyContent(FlexAlign.Center)
  10. .alignItems(HorizontalAlign.Center)
  11. .flexGrow(1)
  12. Image($r('app.media.ic_title'))
  13. .width($r('app.float.text_image_width'))
  14. .height($r('app.float.text_image_height'))
  15. .objectFit(ImageFit.Contain)
  16. Text($r('app.string.splash_desc'))
  17. .fontColor('#66000000')
  18. .fontSize($r('app.float.bigger_font_size'))
  19. .letterSpacing(16)
  20. .margin({ top: $r('app.float.vp_twelve'), bottom: $r('app.float.splash_text_margin_bottom') })
  21. }
  22. .height('100%')
  23. .width('100%')
  24. .backgroundColor('#f1f3f5')}aboutToAppear() {this.timeOutId = setTimeout(() => {router.replaceUrl({ url: 'pages/MainPage' }).catch((err: Error) => {console.error(JSON.stringify(err));})}, 2000);}aboutToDisappear() {clearTimeout(this.timeOutId);}}
复制代码
末了

如果你想快速提升鸿蒙技术,那么可以直接领取这份包罗了:【OpenHarmony多媒体技术、Stage模型、ArkUI多端部署、分布式应用开辟、音频、视频、WebGL、Napi组件、OpenHarmony内核、Harmony南向开辟、鸿蒙项目实战】等技术知识点。
鸿蒙Next全套VIP学习资料←点击领取!(安全链接,放心点击
1.鸿蒙核心技术学习路线

   

  
  2.大厂面试必问面试题


3.鸿蒙南向开辟技术


 4.鸿蒙APP开辟必备


 5.HarmonyOS Next 最新全套视频教程



 6.鸿蒙生态应用开辟白皮书V2.0PDF


这份全套完整版的学习资料已经全部打包好,朋友们如果需要可以点击 鸿蒙Next全套VIP学习资料免费领取(安全链接,放心点击


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4