1

我正在使用常见的 JS 制作一个可滚动的菜单。

菜单项是一个包含其他 2 个组件的视图:一个用于图标的 imageView,一个用于该菜单文本的标签。

在 android 和 ios 模拟器上的行为很奇怪,而且不一样。

在 android 上,如果在标签或 imageview 上单击,则会给出:“未捕获的 TypeError:无法读取属性...”在 iphone 上,它只是不启动任何东西。

如果我点击其他地方(仍然进入查看项目)但不是在图像或唇上,例如在边缘上,那就完美了!

这是代码:

功能菜单图标(itemTab){

var menuMain = Ti.UI.createView({
    layout : 'vertical',
    backgroundColor : '#333333',
    height : 125,
    bottom : 10,
    left : 10,
    right : 10,
    borderRadius : 5.0
});

var menuFirstLine = Ti.UI.createScrollView({
    scrollType : 'horizontal',
    contentHeight : 120,
    contentWidth : 'auto',
    layout : 'horizontal',
    height : 120,
    marginLeft : 5
});

var items = [];
var menuIconsItem = require('view/module/menuIconsItem');

for(var i in itemTab) {
    var page = itemTab[i].page;

    items[i] = new menuIconsItem(itemTab[i]);

    (function(itemsEvent) {
        itemsEvent.id = itemTab[i].id;
        itemsEvent.addEventListener('click', function(e) {

            Ti.App.fireEvent('main_menu_' + itemsEvent.id, {
                id : e.source.id
            });
        })
    })(items[i]);

    menuFirstLine.add(items[i]);
}
menuMain.add(menuFirstLine);
return menuMain;

}

module.exports = 菜单图标;

以及所需项目的代码 (var menuIconsItem = require('view/module/menuIconsItem');) :

功能菜单图标项目(项目){

// path for images on Android  besoin de centraliser tout ca
var pathImages = '';

var itemImage = Ti.UI.createImageView({
    image : item.imageLink,
    width : 64,
    height : 64,
    top : 15
});

var itemLabel = Ti.UI.createLabel({
    color : '#afafaf',
    text : item.text,
    font : {
        textAlign : 'center'
    },
    height : 40,
    top : 80
});

var menuItem = Ti.UI.createView({
    width : 120,
    height : 120,
    backgroundColor : '#424242',
    top : 5,
    left : 5
});

menuItem.add(itemImage);
menuItem.add(itemLabel);

return menuItem;

}

module.exports = menuIconsItem;

4

1 回答 1

2

您还必须为标签和图像视图设置 id。

于 2012-05-11T12:41:41.670 回答