#鸿蒙通关秘籍#怎样在HarmonyOS中为组件设置不同的转场效果?

HarmonyOS
20h前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
CISO梦诗

可以通过不同的转场属性来设置组件的显示和消失效果:

  1. 定义并设置转场属性:
    ArkUI_NodeHandle image = nodeAPI->createNode(ARKUI_NODE_IMAGE);
    // 旋转转场效果
    ArkUI_NumberValue rotateAnimationValue[] = {0.0f, 0.0f, 1.0f, 360.0f, 0.0f, {.i32 = 500}, {.i32 = static_cast<int32_t>(ARKUI_CURVE_SHARP)}};
    ArkUI_AttributeItem rotateAnimationItem = {.value = rotateAnimationValue,
                                               .size = sizeof(rotateAnimationValue) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(image, NODE_ROTATE_TRANSITION, &rotateAnimationItem);
    // 缩放转场效果
    ArkUI_NumberValue scaleAnimationValue[] = {
        0.0f, 0.0f, 0.0f, {.i32 = 500}, {.i32 = static_cast<int32_t>(ARKUI_CURVE_SHARP)}};
    ArkUI_AttributeItem scaleAnimationItem = {.value = scaleAnimationValue,
                                               .size = sizeof(scaleAnimationValue) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(image, NODE_SCALE_TRANSITION, &scaleAnimationItem);
    // 平移动画设置
    ArkUI_NumberValue translateAnimationValue[] = {
        200, 200, 0.0f, {.i32 = 500}, {.i32 = static_cast<int32_t>(ARKUI_CURVE_SHARP)}};
    ArkUI_AttributeItem translateAnimationItem = {.value = translateAnimationValue,
                                                  .size = sizeof(translateAnimationValue) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(image, NODE_TRANSLATE_TRANSITION, &translateAnimationItem);
    
分享
微博
QQ
微信
回复
17h前
相关问题
怎样TextArea组件设置最小高度?
380浏览 • 1回复 待解决