这是 Appcelerator Titanium Mobile 应用程序的简单代码,它几乎可以正常工作,但是...
var drag = require('ti.draggable');
var win = Ti.UI.createWindow({exitOnClose: true, backgroundColor: 'black', navBarHidden: true});
var view1 = Ti.UI.createView({
left: 0,
width: '50%',
height: '100%',
backgroundColor: '#9966cc'
});
win.add(view1);
var dragView = drag.createView({
backgroundColor: '#99cc33',
left: 50, top: 50,
width: 50,
height: 50,
zIndex: 5
});
dragView.addEventListener('start', function(e){
var p = {x: e.source.left, y: e.source.top};
var tp = e.source.parent.convertPointToView(p, win);
e.source.parent.remove(e.source);
e.source.left = tp.x;
e.source.top = tp.y;
win.add(e.source);
});
dragView.addEventListener('end', function(e){
var p = {x: e.left, y: e.top};
var tp = win.convertPointToView(p, view2);
if(tp.x < 0){
tp = win.convertPointToView(p, view1);
e.source.parent.remove(e.source);
e.source.left = tp.x;
e.source.top = tp.y;
view1.add(e.source);
}else{
e.source.parent.remove(e.source);
e.source.left = tp.x;
e.source.top = tp.y;
view2.add(e.source);
}
});
view1.add(dragView);
var view2 = Ti.UI.createView({
left: '50%',
width: '50%',
height: '100%',
backgroundColor: '#cc6699'
});
win.add(view2);
win.open();
如果我的dragView从view1拖到view2,并且dragView.left = 100,dragView.top = 100,那么当我再次尝试拖动它时,它会在win时跳转到相同的坐标。这是为什么?