HarmonyOS 如何实现半屏展开

APP开发中需要实现半屏展开,需求如图所示:

HarmonyOS 如何实现半屏展开-鸿蒙开发者社区

HarmonyOS
2024-09-03 11:04:45
1008浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

您看下以下demo能否实现您的需求:

@Entry 
@Component 
struct SideBarContainerDemo { 
  @State arr: string[] = ['通用设置', '举报反馈', '关于我们'] 
  @State current: number = 1 
  @State showSideBar: boolean = false 
  @State showFlag: Visibility = Visibility.Hidden; 
  // 延迟关闭侧边栏,让自定义的出场动画显示 
  cancel() { 
    this.showFlag = Visibility.Hidden 
    setTimeout(() => { 
      this.showSideBar = !this.showSideBar 
    }, 1000) 
  } 
  build() { 
    SideBarContainer(SideBarContainerType.Overlay) { 
      Column() { 
        ForEach(this.arr, (item: number) => { 
          Column({ space: 5 }) { 
            Text(item+'') 
              .fontSize(25) 
              .fontColor(this.current === item ? '#0A59F7' : '#999') 
              .fontFamily('source-sans-pro,cursive,sans-serif') 
          } 
          .onClick(() => { 
            this.current = item 
          }) 
        }, (item: string) => item) 
      } 
      .visibility(this.showFlag) 
      .transition(TransitionEffect.OPACITY.animation({ duration: 500 }) 
        .combine(TransitionEffect.translate({ x: -100 }))) 
      .width('100%') 
      .justifyContent(FlexAlign.SpaceEvenly) 
      .backgroundColor(Color.Pink) 
      Column() { 
        Button('打开侧边栏').onClick(() => { 
          this.showFlag = Visibility.Visible 
          this.showSideBar = true 
        }) 
        Button('关闭侧边栏').onClick(() => { 
          this.cancel() 
        }) 
      } 
      .backgroundColor(Color.Green) 
      .gesture( 
        TapGesture({ count: 2 }) 
          .onAction((event?: GestureEvent) => { 
            if (event) { 
              this.cancel() 
            } 
          }) 
      ) 
    } 
    .sideBarPosition(SideBarPosition.Start) 
    .showSideBar(this.showSideBar) 
    .showControlButton(false) 
    .sideBarWidth(300) 
    .minSideBarWidth(50) 
    .maxSideBarWidth(300) 
    .minContentWidth(0) 
    .onChange((value: boolean) => { 
      console.info('status:' + value) 
    }) 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
分享
微博
QQ
微信
回复
2024-09-03 15:02:43


相关问题
HarmonyOS 如何实现页面?
749浏览 • 1回复 待解决
HarmonyOS 如何监听折叠展开折叠
886浏览 • 1回复 待解决
HarmonyOS 时间弹窗
596浏览 • 1回复 待解决
如何展示一个广告
1462浏览 • 1回复 待解决
HarmonyOS 希望提供浮层Demo
558浏览 • 1回复 待解决
如何通过路由的方式打开
790浏览 • 1回复 待解决
如何实现文本展开收起功能
1409浏览 • 1回复 待解决
HarmonyOS 如何实现展开的listview功能
535浏览 • 1回复 待解决