PopWindow的效果实现有哪些?

PopWindow的效果实现

HarmonyOS
2024-05-26 11:29:36
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
morning_dxm

PopUpMenu组件能做到下图左部分,但是开发中期望效果是右部分。此时就无法完全依赖官网的PopUp组件的能力了,需要进行特殊处理。

1) 需要自定义PopUp的弹窗

@CustomDialog 
struct CustomDialogExample { 
  controller: CustomDialogController 
  cancel: () => void 
  confirm: () => void 
 
  build() { 
    Column() { 
      Column() { 
        RelativeContainer() { 
          Menu() { 
            MenuItem({ startIcon: $r("app.media.scanning"), content: "扫一扫" }) 
              .margin({ 
                top: 40, 
                bottom: 0 
              }) 
 
            MenuItem({ startIcon: $r("app.media.versions"), content: "版本切换" }) 
            MenuItem({ startIcon: $r("app.media.code"), content: "收付款" }) 
            MenuItem({ startIcon: $r("app.media.online_service"), content: "在线客服" }) 
            MenuItem({ startIcon: $r("app.media.net_service"), content: "网络客服" }) 
            MenuItem({ startIcon: $r("app.media.elimination"), content: "消保专区" }) 
          } 
          .id("row1") 
          .alignRules({ 
            top: { anchor: 'row2', align: VerticalAlign.Bottom }, 
            left: { anchor: '__container__', align: HorizontalAlign.Start } 
          }) 
 
          Column() { 
            Image($r('app.media.plus')) 
              .width(30) 
              .height(30) 
              .rotate({ angle: 45 }) // .bindMenu(this.MyMenu) 
          } 
          .height(0) 
          .id('row2') 
          .alignRules({ 
            top: { anchor: '__container__', align: VerticalAlign.Top }, 
            right: { anchor: '__container__', align: HorizontalAlign.End } 
          }) 
          .backgroundColor(Color.Black) 
        } 
      } 
      .size({ width: 150, height: 350 }) 
    }.width(150) 
    .animation({ duration: 2000, delay: 0, curve: Curve.Ease }) 
  } 
}
  • 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.

2) 定义右上角的Circle-Plus符号,并绑定1) 中的自定义弹窗

@Builder 
roatedCircle() { 
  RelativeContainer() { 
    Image($r('app.media.plus')) 
      .width(30) 
      .height(30) 
      .objectFit(ImageFit.Fill) 
      .rotate({ angle: this.rotateValue })// .bindMenu(this.MyMenu) 
      .onClick(() => { 
        this.animate = !this.animate; 
 
        animateTo({ curve: curves.springMotion() }, () => { 
          // this.rotateValue = this.animate ? 45 : 0; 
          this.rotateValue = 0; 
        }); 
 
        this.dialogController = new CustomDialogController({ 
          builder: CustomDialogExample({ 
            cancel: this.onCancel, 
            confirm: this.onAccept, 
          }), 
          alignment: DialogAlignment.TopStart, 
          // offset: { dx: 235, dy: 40 }, // 真机位置 
          offset: { dx: 210, dy: 0 }, // 预览器位置 
          customStyle: true 
        }) 
 
        if (this.dialogController != undefined) { 
          this.dialogController.open() 
          this.dialogController 
          this.flag = true 
        } 
      }) 
      .onBlur(() => { 
      }) 
      .id('row1') 
      .visibility(this.flag ? Visibility.Visible : Visibility.Hidden) 
      .alignRules({ 
        top: { anchor: '__container__', align: VerticalAlign.Top }, 
        right: { anchor: '__container__', align: HorizontalAlign.End } 
      }) 
  } 
}
  • 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.

3) 构造build函数,完成demo

import curves from '@ohos.curves'; 
 
@Entry 
@Component 
struct Index { 
  @State message: string = 'Hello World'; 
  @State select: boolean = true 
  @State rotateValue: number = 0 
  @State animate: boolean = false 
  @State flag: boolean = true 
  dialogController: CustomDialogController = new CustomDialogController({ 
    builder: CustomDialogExample({ 
      cancel: this.onCancel, 
      confirm: this.onAccept, 
    }), 
    alignment: DialogAlignment.TopStart, 
    offset: { dx: 0, dy: 0 } 
  }) 
 
  onCancel() { 
    this.flag = false 
    console.info('Callback when the first button is clicked') 
  } 
 
  onAccept() { 
    console.info('Callback when the second button is clicked') 
  } 
 
  existApp() { 
    console.info('Click the callback in the blank area') 
  } 
 
  build() { 
    // Button('click for Menu') 
    Row() { 
      this.roatedCircle() 
    } 
    .justifyContent(FlexAlign.Center) 
  } 
}
  • 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.
分享
微博
QQ
微信
回复
2024-05-27 11:40:39


相关问题
HarmonyOS clipShape 动画效果实现
165浏览 • 0回复 待解决
HarmonyOS 效果实现方案
1082浏览 • 1回复 待解决
HarmonyOS 动画效果实现
620浏览 • 1回复 待解决
HarmonyOS list选中效果实现
278浏览 • 1回复 待解决
HarmonyOS 首页轮播效果实现
303浏览 • 1回复 待解决
HarmonyOS 类似翻页效果实现
676浏览 • 1回复 待解决
引导遮罩效果实现最佳方案
1780浏览 • 1回复 待解决
动态布局下加载loading效果实现
1268浏览 • 1回复 待解决
Binder链接池实现有哪些方法?
1010浏览 • 1回复 待解决
HarmonyOS 如何实现有符号数组
568浏览 • 0回复 待解决
Scrollerfling实现有什么好方案
1113浏览 • 1回复 待解决
HarmonyOS 现有组件扩展如何实现
307浏览 • 1回复 待解决