Kevin Rignault Kevin Rignault - 1 year ago 147
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});

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 Source

Does this work for you? Properties on the view object found at!/api/Titanium.UI.View

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download