在 Appcelerator Titanium 中获取视图的相对位置
Get relative position of view in Appcelerator Titanium
我正在尝试使用 Appcelerator Titanium 获取 ImageView 在视图中的相对位置。
我的代码:
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);
我想知道 imgView 在 touchmove 事件中在 contentView 中的位置:
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 ?
});
你有什么想法吗?谢谢:)
imgView.rect.x
imgView.rect.y
这对你有用吗?在 http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.View
处找到的视图对象的属性
我正在尝试使用 Appcelerator Titanium 获取 ImageView 在视图中的相对位置。
我的代码:
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);
我想知道 imgView 在 touchmove 事件中在 contentView 中的位置:
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 ?
});
你有什么想法吗?谢谢:)
imgView.rect.x
imgView.rect.y
这对你有用吗?在 http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.View
处找到的视图对象的属性