0

こんにちは、stackoverflow とネイティブ スクリプトのユーザーです。

ビューのアニメーション化に問題があります。

私が欲しいもの:クリックできるビューを作成しようとしています。それは、アニメーションの下にある新しいビューを開き、他のすべてのビューをさらに下に押します。

問題: 内部の要素だけがアニメーション化されているか、何もアニメーション化されていません。

試したこと: ネイティブ スクリプトのUI アニメーションを使用してみましたが、height プロパティがサポートされていないため成功しませんでした。

私のバージョン: https://gyazo.com/130c2b3467656bcc104c9b8e2c860d94

これに取り組むために皆さんが思いついた解決策を聞きたいです。

4

1 に答える 1

2

tweenjs に依存する次のクラスを定義するネイティブ スクリプト アプリケーションで tweenjs を使用できます ( でインストールしますnpm i @tweenjs/tween.js) 。

import * as TWEEN from '@tweenjs/tween.js';
export { Easing } from '@tweenjs/tween.js';

TWEEN.now = function () {
    return new Date().getTime();
};

export class Animation extends TWEEN.Tween {
    constructor(obj) {
        super(obj);
        this['_onCompleteCallback'] = function() {
            cancelAnimationFrame();
        };
    }
    start(time) {
        startAnimationFrame();
        return super.start(time);
    }
}

let animationFrameRunning = false;
const cancelAnimationFrame = function() {
    runningTweens--;
    if (animationFrameRunning && runningTweens === 0) {
        animationFrameRunning = false;
    }
};

let runningTweens = 0;
const startAnimationFrame = function() {
    runningTweens++;
    if (!animationFrameRunning) {
        animationFrameRunning = true;
        tAnimate();
    }
};
const requestAnimationFrame = function(cb) {
    return setTimeout(cb, 1000 / 60);
};
function tAnimate() {
    if (animationFrameRunning) {
        requestAnimationFrame(tAnimate);
        TWEEN.update();
    }
}

次に、ビューの高さをアニメーション化するには、次のようなメソッドを使用できます (これは nativescript-vue で機能しますが、ビュー オブジェクトを取得する方法を調整する必要があります)。

import {Animation, Easing} from "./Animation"

toggle() {
    let view = this.$refs.panel.nativeView
    if (this.showPanel) {
        new Animation({ height: this.fixedHeight })
            .to({ height: 0 }, 500)
            .easing(Easing.Back.In)
            .onUpdate(obj => {
                view.originY = 0
                view.scaleY = obj.height / this.fixedHeight;
                view.height = obj.height;
            })
            .start()
            .onComplete(() => this.showPanel = !this.showPanel);
    } else {
        this.showPanel = !this.showPanel
        new Animation({ height: 0 })
            .to({ height: this.fixedHeight }, 500)
            .easing(Easing.Back.Out)
            .onUpdate(obj => {
                view.originY = 0
                view.scaleY = obj.height / this.fixedHeight;
                view.height = obj.height;
            })
            .start();
    }
}

これはここで議論されました: https://github.com/NativeScript/NativeScript/issues/1764onUpdate私は主にアニメーションを滑らかにするため に改善しました

于 2018-11-01T18:26:47.247 に答える