2

我在 Titanium 中开发了一个应用程序。一个带有可滚动视图的代码。它在 Android 中工作,但在 IOS 中不工作,并且不显示错误消息。编码:

exports.imagescroller = function(images, imgWidth, imgHeight){

var imageCollection = images;
var window = Ti.UI.createWindow({
    backgroundColor:'transparent',

});
if(imgWidth == null) {
    imgWidth = "100%";  
}

if(imgHeight == null) {
    imgHeight = "100%";
}

var scrollGallery = Ti.UI.createScrollableView({
    layout:'horizontal',
    showHorizontalScrollIndicator:true,
    showVerticalScrollIndicator:true,
});
var viewCollection = [];

for (var i = 0; i < imageCollection.length; i++) {
  var innerView = Ti.UI.createView({
    layout:'horizontal',
  });
  var item = Ti.UI.createImageView({
        width : imgWidth,
        height: imgHeight,
        imageID:i,
        defaultImage: imageCollection[0]
  });
  if (i < 3) {
    item.image = imageCollection[i];
  }

  innerView.add(item);
  viewCollection.push(innerView);
}

scrollGallery.addEventListener('scroll', function(e){
    if (scrollGallery.currentPage < (imageCollection.length-1)) {
        var nxt = scrollGallery.currentPage+1;
        scrollGallery.views[nxt].children[0].image = imageCollection[nxt];
    }
});
scrollGallery.views = viewCollection;

window.add(scrollGallery);
return window;

};

我在窗口中使用它:

var Scroller = require("imagescroller");

window = Scroller.imagescroller(allData['images']);

请帮我!谢谢!

4

3 回答 3

1

尝试使用更跨平台的scrollend事件:

scrollGallery.addEventListener('scrollend', function(e){
    .......
});

也尝试给你的 ScrollableView 一个明确的宽度和高度,只是为了排除:

var scrollGallery = Ti.UI.createScrollableView({
    layout:'horizontal',
    showHorizontalScrollIndicator:true,
    showVerticalScrollIndicator:true,
    width : "100%"
    height : "100%"
});
于 2014-03-05T12:54:39.970 回答
1

试试这个及其工作,在发布之前我尝试过。

var win = Ti.UI.createWindow();

var view1 = Ti.UI.createView({
    backgroundColor : '#123'
});
var view2 = Ti.UI.createView({
    backgroundColor : '#246'
});
var view3 = Ti.UI.createView({
    backgroundColor : '#48b'
});

var scrollableView = Ti.UI.createScrollableView({
    views : [view1, view2, view3],
    showPagingControl : true,
    layout : 'horizontal',
    showHorizontalScrollIndicator : true,
    showVerticalScrollIndicator : true,
});

win.add(scrollableView);
win.open();
于 2017-02-27T10:48:05.287 回答
-1

当您设置视图的高度超过屏幕或设置视图的高度时,它在 android 中有效,Ti.UI.SIZE 它有效

于 2017-02-27T09:55:57.093 回答