【发布时间】:2017-02-12 14:19:49
【问题描述】:
我想在钛应用加速器中垂直拖动视图并在屏幕上显示整个视图高度时停止。 在开始时,视图的高度为 140,底部为 -120,所以我可以有一个可以开始拖动的视图:
这就是我想要垂直拖动“myView”的方式,x 轴保留为 0,所以我只能从下到上拖动它,目的是在显示所有 myView 高度时停止拖动(所有 myView 都是可见的) .
var WIDTH = (OS_ANDROID) ? Ti.Platform.displayCaps.platformWidth / dpi : Ti.Platform.displayCaps.platformWidth;
var HEIGHT = (OS_ANDROID) ? Ti.Platform.displayCaps.platformHeight / dpi : Ti.Platform.displayCaps.platformHeight;
var sx = 0;
var sy = 0;
var cx = 0;
var cy = 0;
var xDistance = 0;
function onTouchStart(e) {
// start movement
sx = e.x;
sy = e.y;
cx = e.x;
cy = e.y;
console.log(e.x);
}
function onTouchMove(e) {
xDistance = cx - sx;
var yDistance = cy - sy;
var points = e.source.convertPointToView({
x: e.x,
y: e.y
}, $.single);
$.myView.applyProperties({
left: 0,
top: points.y,
opacity: 1
});
/*------------------------------------------------------
* HERE I TRY TO DETECT IF myView HEIGHT IS SHOWN ENTIRELY
* is myView.top + myView.height > viewport ?
------------------------------------------------------*/
var t = $.myView.top + $.myView.height;
if( t >= HEIGHT ){
alert('all myView is visible now ???');
return; // <= why this has no effect ??
}
cx = e.x;
cy = e.y;
}
function onTouchEnd(e) {
// check xDistance
}
$.myView.addEventListener("touchmove", onTouchMove);
$.myView.addEventListener("touchstart", onTouchStart);
$.myView.addEventListener("touchend", onTouchEnd);
使用此代码,我可以垂直拖动 myView,但在完全显示此高度时它不会停止。
我的第一个问题是: - 我怎么能说 myView 是否完全显示? - 如果显示所有 myView 高度,如何禁用垂直拖动到顶部?
谢谢
【问题讨论】:
标签: titanium appcelerator appcelerator-titanium appcelerator-mobile