Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Move image to top left of screen

I am developing a mobile app and I am trying to animate an imageView from its default position (about the middle of the screen) to the top left of the screen, while shrinking it.

Here's what I have…

t = Ti.UI.create2DMatrix();
t = t.scale(size);
var asdf=Ti.UI.createAnimation({
   transform:t,
   top:0,
   left:0,
   duration:1000
});
img.animate(asdf);

This scales the image down but does not move it.

So my question is two-fold. First, how do I find the top left of the window. Second, how do I get something to move there?

— asked April 6th 2010 by Brant Steen
  • animate
  • animation
  • layout
  • mobile
0 Comments

1 Answer

  • For movement, you'd want to use translate on your matrix

    So, you could do something like

    t = Ti.UI.create2DMatrix();
    t = t.scale(size).translate(100,-100);
    

    Play around with those values to get both a scale (increase/decrease in size) and translate(movement of x,y)

    To go back to the previous transform, you can simply create an empty 2DMatrix and pass it back to animate again. This is called the identity matrix.

    — answered April 6th 2010 by Jeff Haynie
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.