我在以下代码中创建了一个标签。现在我想获取标签的当前中心坐标,而无需显式设置中心。
我怎样才能做到这一点?
var label = Ti.UI.createLabel({width:400, height:400});
最佳答案
您必须等到 View 布局完成,因此为 postlayout
设置一个监听器事件,然后使用更新的rect
值来计算中心。
label.addEventListener('postlayout', function(e) {
// Calculate the center using the RO rect property
var center = {
x : rect.x + rect.width / 2,
y : rect.y + rect.height / 2
};
// Do what you ned to do with that....
});
关于ios - 获取隐式中心值 Titanium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17781725/