Kevin Rignault Kevin Rignault - 5 months ago 34
Javascript Question

Get relative position of view in Appcelerator Titanium

I'm trying to get the relative position of an ImageView in a View with Appcelerator Titanium.

My code :

var contentView = Ti.UI.createView({width:300,height:300,backgroundColor:"red"});
var imgView = Ti.UI.createImageView({image:'image.png', height:100, width:100, zIndex:5});
contentView.add(imgView);
win.add(contentView);


I want to know the position of the imgView in the contentView during a touchmove event :

var olt = Ti.UI.create3DMatrix(), curX, curY;

imgView.addEventListener('touchstart', function(e) {
curX = e.x;
curY = e.y;
});

imgView.addEventListener('touchmove', function(e) {
var deltaX = e.x - curX;
var deltaY = e.y - curY;

olt = olt.translate(deltaX, deltaY, 0);
imgView.animate({transform:olt, duration:100});

//-- top/left position of the imgView ?
});


Do you have any ideas please ? Thanks :)

Answer
imgView.rect.x
imgView.rect.y

Does this work for you? Properties on the view object found at http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.View

Comments