HarmonyOS CAPI动画怎么使用?

HarmonyOS CAPI动画怎么使用?

HarmonyOS
2024-10-08 10:27:34
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa

请参考以下代码:

static ArkUI_NodeHandle textInput = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT);  
ArkUI_NativeAnimateAPI_1 *animateApi = nullptr;  
OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_ANIMATE, ArkUI_NativeAnimateAPI_1, animateApi);  
OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager",  
  "CreateNativeNode  animateApi = %{public}p", animateApi);  
ArkUI_AnimateOption *option = OH_ArkUI_AnimateOption_Create();  
OH_ArkUI_AnimateOption_SetDuration(option, 2000);  
OH_ArkUI_AnimateOption_SetTempo(option, 1.1);  
OH_ArkUI_AnimateOption_SetCurve(option, ARKUI_CURVE_EASE);  
OH_ArkUI_AnimateOption_SetDelay(option, 20);  
OH_ArkUI_AnimateOption_SetIterations(option, 1);  
OH_ArkUI_AnimateOption_SetPlayMode(option, ARKUI_ANIMATION_PLAY_MODE_REVERSE);  
ArkUI_ExpectedFrameRateRange *range = new ArkUI_ExpectedFrameRateRange;  
range->min = 10;  
range->max = 120;  
range->expected = 60;  
OH_ArkUI_AnimateOption_SetExpectedFrameRateRange(option, range);  
struct AA {  
  int32_t a;  
};  
AA *onFinishUser = new AA;  
onFinishUser->a = 101;  
ArkUI_AnimateCompleteCallback *completeCallback = new ArkUI_AnimateCompleteCallback;  
completeCallback->userData = onFinishUser;  
completeCallback->type = ARKUI_FINISH_CALLBACK_REMOVED;  
               completeCallback->callback = [](void *userData) {  
                   OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager",  
                                "CreateNativeNode  onFinishCallback %{public}d", reinterpret_cast<AA *>(userData)->a);  
               };  
               AA *eventUser = new AA;  
               eventUser->a = 201;  
               static bool isback = true;  
               ArkUI_ContextCallback *update = new ArkUI_ContextCallback;  
               update->userData = eventUser;  
               update->callback = [](void *user) {  
                   OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "Manager",  
                                "CreateNativeNode  animateTo %{public}d", reinterpret_cast<AA *>(user)->a);  
                   // width height  
                   if (isback) {  
                       ArkUI_NumberValue custom_widthValue[] = {200};  
                       ArkUI_AttributeItem custom_widthItem = {custom_widthValue, 1};  
                       ArkUI_NumberValue custom_heightValue1[] = {80};  
                       ArkUI_AttributeItem custom_heightItem1 = {custom_heightValue1, 1};  
                       nodeAPI->setAttribute(textInput, NODE_WIDTH, &custom_widthItem);  
                       nodeAPI->setAttribute(textInput, NODE_HEIGHT, &custom_heightItem1);  
                   } else {  
                       ArkUI_NumberValue custom_widthValue[] = {100};  
                       ArkUI_AttributeItem custom_widthItem = {custom_widthValue, 1};  
                       ArkUI_NumberValue custom_heightValue1[] = {40};  
                       ArkUI_AttributeItem custom_heightItem1 = {custom_heightValue1, 1};  
                       nodeAPI->setAttribute(textInput, NODE_WIDTH, &custom_widthItem);  
                       nodeAPI->setAttribute(textInput, NODE_HEIGHT, &custom_heightItem1);  
                   }  
               };  
               animateApi->animateTo(context, option, update, completeCallback);  
               OH_NativeXComponent_AttachNativeRootNode(component, stack);
分享
微博
QQ
微信
回复
2024-10-08 17:10:36
相关问题
HarmonyOS 属性动画怎么监听帧回调?
306浏览 • 1回复 待解决
救命,鸿蒙怎么动画
5747浏览 • 2回复 待解决
如何使用弹簧动画曲线
624浏览 • 1回复 待解决
HarmonyOS RN三方库列表对应CAPI库列表
466浏览 • 1回复 待解决
鸿蒙中怎么实现动画翻转效果
10519浏览 • 2回复 待解决
HarmonyOS 动画需求
25浏览 • 1回复 待解决
提问
该提问已有0人参与 ,帮助了0人