move view from point A to point B using Animation

You must Login before you can answer or comment on any questions.

Hi there,

I have this codes to enlarge an image and move it from original center to the window's center. It works on SDK 1.8 before. But after transition to SDK2.0, I have no idea why it doesn't work anymore. The scaling part work, but the center of the view doesn't move.

var shelf = Ti.UI.createView({
    backgroundColor:'yellow',
    height:Ti.UI.FILL,
    width:Ti.UI.FILL,
    top:0,
    left:0,
});
//--- The view need to be moved
var selectedImage = Ti.UI.createView({
            backgroundColor:'green',
            width: 100,
            height: 100,
            left: 0,
            top: 0
        }); 
selectedImage.addEventListener('click', function(e){
    selectedImage.animate(a);
 
});
shelf.add(selectedImage);
Ti.UI.currentWindow.add(shelf);
 
//----Animation
var t = Titanium.UI.iOS.create3DMatrix();
t = t.scale(4);
 
var a = Titanium.UI.createAnimation({
    transform:t,
    center: {x:400, y:400}, 
    duration: 500
});

I am testing on iPad Simulator. Anyone, any clue?

Thanks a lot in advance.

— asked 12 months ago by Bowie Poon
0 Comments

2 Answers

Not sure but try to make the view setting the center instead of the left/top. Maybe this is the issue - center undefined

Anyway looks like a bug to me.

— answered 12 months ago by Dan Tamas
answer permalink
2 Comments
  • Tried that too, but no luck.

    Thanks anyway, Dan.

    — commented 12 months ago by Bowie Poon

  • Maybe because you are adding a transform the movement needs to be done inside the 3d matrix?

    Try to use translate inside the transform, just like scale.

    http://docs.appcelerator.com/titanium/2.0/index.html#!/api/Titanium.UI.3DMatrix-method-translate

    — commented 12 months ago by Dan Tamas

Hello Bowie,

Try this way, it's work fine for me...

var win = Ti.UI.currentWindow;
 
var shelf = Ti.UI.createView({
    backgroundColor : 'yellow',
    height : Ti.UI.FILL,
    width : Ti.UI.FILL,
    top : 0,
    left : 0,
});
//--- The view need to be moved
var selectedImage = Ti.UI.createView({
    backgroundColor : 'green',
    width : 100,
    height : 100,
    left : 0,
    top : 0
});
selectedImage.addEventListener('click', function(e) {
    selectedImage.animate(a);
});
shelf.add(selectedImage);
win.add(shelf);
 
var a = Ti.UI.createAnimation();
a.top = 150;
a.left = 110;
a.duration = 5000;

Your Answer

Think you can help? Login to answer this question!