Анимационные размеры в Sencha Touch 2 - PullRequest
4 голосов
/ 26 марта 2012

Я пытаюсь анимировать высоту отображения данных, но в настоящее время она просто перемещает панель вокруг области просмотра вместо того, чтобы удерживать ее на месте и изменять ее высоту.Код выглядит следующим образом:

Ext.Anim.run(el, 'slide', {
  from: { height: height },
  to: { height: newHeight },
  out: false,
  direction: 'up',
  easing: 'ease-out',
  duration: 1000
});

Например, высота = 200, newHeight = 100 приведет к немедленному отбрасыванию отображения данных, так что его вершина окажется на 200 пикселей ниже области просмотра, а затем анимирована обратно к вершине.окна просмотра.

Как мне получить его, чтобы изменить высоту?Спасибо.

Ответы [ 3 ]

9 голосов
/ 26 марта 2012

Попробуйте использовать Ext.Animator.run вместо:

Ext.Animator.run({
    element: dataview.element,
    duration: 500,
    easing: 'ease-in',
    preserveEndState: true,
    from: {
        height: dataview.element.getHeight()
    },
    to: {
        height: 100
    }
});

И в полном примере:

Ext.application({
    name: 'Sencha',

    launch: function() {
        var dataview = Ext.create('Ext.DataView', {
            fullscreen: true,
            style: 'background:red',
            store: {
                fields: ['text'],
                data: [
                    { text: 'one' },
                    { text: 'two' },
                    { text: 'three' }
                ]
            },
            itemTpl: '{text}'
        });

        Ext.Viewport.add({
            xtype: 'button',
            docked: 'top',
            handler: function() {
                Ext.Animator.run({
                    element: dataview.element,
                    duration: 500,
                    easing: 'ease-in',
                    preserveEndState: true,
                    to: {
                        height: 100
                    },
                    from: {
                        height: dataview.element.getHeight()
                    }
                });
            }
        });
    }
});
1 голос
/ 30 октября 2012

Поскольку я не могу добавлять комментарии, мне придется поместить это как отдельный ответ.Я просто хотел добавить к тому, что сказал rdougan, и показать, как вы можете поймать событие окончания анимации.Я считаю, что это необходимо в описанной выше ситуации, потому что функции component.getTop / Left / Height / Width () Sencha Touch возвращают неправильные значения после анимации, такой как показанная.

dataview.setHeight(dataview.element.getHeight()); // you may or may not need this

console.log('height before\t', dataview.getHeight());

var a = new Ext.fx.Animation({
    element: dataview.element,
    duration: 500,
    easing: 'ease-in',
    preserveEndState: true,
    from: {
        height: dataview.element.getHeight()
    },
    to: {
        height: 100
    }
});

a.on('animationend', function (animation, element, isInterrupted) {
    console.log('height before\t', dataview.getHeight());
    dataview.setHeight(dataview.element.getHeight());
    console.log('height set\t', dataview.getHeight());
});

Ext.Animator.run(a);

Я оставил в некоторых журналах такВы можете видеть только то, что я имею в виду.Этот пример был написан против ST 2.1 RC2.

0 голосов
/ 29 декабря 2012

Вот чистая служебная функция, которую вы можете использовать для этого

function animatron (target, prop, duration, to, from, easing) {
    // return if no target or prop
    if (target == null || prop == null) { return; }

    // defaults
    if (duration == null) { duration = 250; }
    if (to == null) { to = 0; }
    if (from == null) { from = target.getHeight(); }
    if (easing == null) { easing = 'ease-out'; }

    // to property
    var t = {};
    t[prop] = to;

    // from property
    var f = {};
    f[prop] = from;

    // Animation Options
    var opts = {
        duration: duration,
        easing: easing,
        element: target.element,
        from: f,
        preserveEndState: true,
        to: t
    };

    // Animation Object
    var anime = new Ext.fx.Animation(opts);

    // On animationend Event
    anime.on('animationend', function (animation, element, isInterrupted) {
        // Hide the target if the to is 0
        if (to == 0 && (prop == 'height' || prop == 'width')) {
            if (!isInterrupted) { target.hide(); }
        }

        // Update property if width or height
        if (prop == 'height') { target.setHeight(to); }
        if (prop == 'width') { target.setWidth(to); }

        // Dispatch 'animated' event to target
        target.fireEvent('animated', animation, element, to, from, isInterrupted);
    });

    // Show the target if it's hidden and to isn't 0
    if (target.getHidden() == true && to != 0) { target.show(); }

    // Run the animation
    Ext.Animator.run(anime);
}

Вы можете прослушать «анимированное» событие на целевом элементе

animatron(dataview, 'height', 500, 0);
dataview.addListener('animated', function (animation, element, to, from, isInterrupted) {
    console.log('animation ended');
    console.log('interrupted: '+ isInterrupted);
});
...