鸿蒙开源组件——动画播放库

jacksky
发布于 2021-12-30 17:15
浏览
0收藏

CanAnimation

项目介绍

  • 项目名称:CanAnimation

  • 所属系列:openharmony的第三方组件适配移植

  • 功能:使用openharmony属性动画写的一个库,可组建动画队列,可实现同时、顺序、重复播放等。

  • 项目移植状态:翻转动画效果未实现,OpenHarmony没有对应的Camera类支持

  • 调用差异:

  • 开发版本:sdk6,DevEco Studio2.2 Beta1

  • 基线版本: Release 1.0.3

效果演示鸿蒙开源组件——动画播放库-鸿蒙开发者社区

安装教程

1.在项目根目录下的build.gradle文件中,

allprojects {
   repositories {
       maven {
           url 'https://s01.oss.sonatype.org/content/repositories/releases/'
       }
   }
}

2.在entry模块的build.gradle文件中,

dependencies {
   implementation('com.gitee.chinasoft_ohos:canAnimation:1.0.0')
   ......  
}

在sdk5,DevEco Studio2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下

使用说明

CanObjectAnimator 属性动画使用代码:

  CanObjectAnimator builder = CanObjectAnimator.on(view);


            animationSequence(builder.moveTo(center.x, center.y, 0),

                    animationTogether(builder.moveTo(center.x,newPos.x,center.y, newPos.y, 2),
                            builder.rotateTo(360, 2)
                          
                    ),
                    animationTogether(builder.scaleTo(0.5f, 0.5f,2),
                            builder.rotateTo(720,2)
                    ),

                    animationTogether(
                            builder.moveTo(newPos.x,center.x, newPos.y,center.y, 2),
                            builder.scaleTo(0.5f,2, 0.5f,2, 2),
                            builder.rotateTo(360, 2)
                    ),

                   CanAnimation.run(new Runnable() {
                        @Override
                        public void run() {
                            if (finalI == 5) {
                                start_animator.setVisibility(Component.VISIBLE);
                            }
                        }
                    })

            ).start();

CanObjectAnimator 普通动画使用代码:

 AnimatorProperty animatorValue = view.createAnimatorProperty();
            animatorValue.moveToX(newPos.getPointX()).moveToY(newPos.getPointY());
            animatorValue.setDuration(2000);
            Animator end = CanAnimation.run(new Runnable() {
                @Override
                public void run() {
                    if (finalI == 5) {
                        start_animator.setVisibility(Component.VISIBLE);
                    }
                }
            });

            CanAnimation.animSmall2Big(view, animatorValue, end).start();

过度动画使用 PageFlipper + AnimatorProperty 实现。使用代码:

 viewFlipper = (PageFlipper) findComponentById(ResourceTable.Id_vf);
        viewFlipper.setTouchEventListener(this::onTouchEvent);
        viewFlipper.setDraggedListener(Component.DRAG_HORIZONTAL_VERTICAL, this);
        viewFlipper.setFlipPeriod(3000);
        viewFlipper.showNext();
        viewFlipper.showPrevious();

        Optional<Display> display = DisplayManager.getInstance().getDefaultDisplay(this);
        DisplayAttributes displayAttributes = display.get().getAttributes();
        int width = displayAttributes.width;


        AnimatorProperty lInAnim = viewFlipper.createAnimatorProperty();
        lInAnim.moveFromX(width).moveToX(0).alphaFrom(0.1f).alpha(1.0f).setDuration(1500);
        AnimatorProperty lOutAnim = viewFlipper.createAnimatorProperty();
        lOutAnim.moveFromX(0).moveToX(-width).alphaFrom(1.0f).alpha(0.1f).setDuration(1500);

        viewFlipper.setIncomingAnimation(lInAnim);
        viewFlipper.setOutgoingAnimation(lOutAnim);

        if (!viewFlipper.isFlipping()) {
            viewFlipper.startFlipping();
        }

测试信息

CodeCheck代码测试无异常

CloudTest代码测试无异常

病毒安全检测通过

当前版本demo功能与原组件基本无差异

版本迭代

  • 1.0.0

版权和许可信息

    Copyright 2016 canyinghao

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

CanAnimation-master.zip 673.83K 4次下载
已于2021-12-30 17:15:28修改
收藏
回复
举报
回复
    相关推荐