1

如何在钛合金中使用左右箭头控制垂直滚动。如何连接滚动视图和左右箭头之间

这是代码:

   var counter = 0;
   rightArrow.addEventListener('click', function(e) {

    counter++;

    var wrapperChild = wrapperView.getChildren();

    var scroll2 = verticalScroll.scrollTo(114, 0);
    var scroll1 = verticalScroll.scrollTo(0, 0);
    var scroll3 = verticalScroll.scrollTo(307, 0);

    if (counter == 1) {
        verticalScroll.scrollTo(114, 0);
        alert(counter);
    } else if (counter == 2) {
        verticalScroll.scrollTo(307, 0);
        alert(counter);
        //}
    } else if (counter == 3) {
        verticalScroll.scrollTo(417, 0);
        alert(counter);
    } else if (counter == 4) {
        verticalScroll.scrollTo(560, 0);
        alert(counter);
    } else if (counter == 5) {
        verticalScroll.scrollTo(672, 0);
        alert(counter);
    }
});

leftArrow.addEventListener('click', function(e) {
    if (counter == 0)  verticalScroll.scrollTo(0, 0);
});

verticalScroll.addEventListener('scroll', function(e) {
     Ti.API.info('Scrollview contents y offset: ' + e.x + 'Scrollview contents y offset: ' + e.y);
});
4

1 回答 1

1

Scrollview 有一个方法称为scrollTo( Number x, Number y ),记录在这里

基本上你必须

  • 创建滚动视图并将其添加到窗口
  • 创建并向窗口添加左右按钮(如果在滚动视图之前添加按钮,则可能必须设置 zIndex)
  • 将 eventListeners 添加到将触发 scrollTo() 的按钮。请参阅“简单按钮示例”

您可能也对 Titaniums ScrollableView感兴趣

于 2013-09-29T11:47:32.520 回答