cocos2dx3.5 中listview item里面有ControlButton滑动失效的问题
来源:互联网 发布:朴宰范 私生活问题知乎 编辑:程序博客网 时间:2024/06/10 21:14
出现的主要情况是 我点击在ControlButton上面滑动的时候 ControlButton会将事件吃掉 所以listview就不会滑动 自己也在网络上面查了一些相关资料 最有用的应该是 这一篇文章 。但是使用了里面的方法 在我的项目之中没用用处,事件依然会被ControlButton吃掉 所以这里使用的方法是 调用ControlButton的setEnabled 为false 然后使用addEventListener 设置selectedItemEvent 方法 在selectedItemEvent方法之中去点击item 这样不会影响滑动和点击 我试着断点看了哈源码目前没有发现是什么原因造成的 也不知在新版本是否有这个问题 如果有谁发现了可以在下面留言告诉我
下面贴上我的源码
mOtherGameListView = cocos2d::ui::ListView::create();mOtherGameListView->setDirection(ui::ScrollView::Direction::VERTICAL);//设置ListView布局方向 mOtherGameListView->setBounceEnabled(false);//设置反弹效果 mOtherGameListView->setAnchorPoint(Vec2(0, 0));mOtherGameListView->setContentSize(Size(m_other_width, 440));mOtherGameListView->setInnerContainerSize(Size(m_other_width, 440));mOtherGameListView->setBackGroundImageScale9Enabled(true);//设置九宫格 mOtherGameListView->setPosition(Vec2(0, 0));mOtherGameListView->ignoreContentAdaptWithSize(false);//开启锚点设置,false可更改锚点,true不可更改,Layer默认为point(0,0),其他Node为Point(0.5,0.5) mOtherGameListView->setGravity(cocos2d::ui::ListView::Gravity::CENTER_VERTICAL);m_other_gameLayer->addChild(mOtherGameListView);mOtherGameListView->addEventListener((ui::ListView::ccListViewCallback)CC_CALLBACK_2(YYNewGameListLayer::selectedItemEvent, this));
这是点击item用到的事件
void YYNewGameListLayer::selectedItemEvent(Ref *pSender, cocos2d::ui::ListView::EventType type){switch (type){case cocos2d::ui::ListView::EventType::ON_SELECTED_ITEM_START:{cocos2d::ui::ListView* listView = static_cast<cocos2d::ui::ListView*>(pSender);CC_UNUSED_PARAM(listView);CCLOG("select child start index = %ld", listView->getCurSelectedIndex());cocos2d::ui::Layout* item = (cocos2d::ui::Layout *)listView->getItem(listView->getCurSelectedIndex());//item->setScale(1.1f);break;}case cocos2d::ui::ListView::EventType::ON_SELECTED_ITEM_END:{cocos2d::ui::ListView* listView = static_cast<cocos2d::ui::ListView*>(pSender);CC_UNUSED_PARAM(listView);cocos2d::ui::Layout* item = (cocos2d::ui::Layout *)listView->getItem(listView->getCurSelectedIndex());if (roomSelectLayer == NULL){onClickGame(item->getTag());}CCLOG("select child end index = %ld", listView->getCurSelectedIndex());break;}default:break;}}
这是添加item
for (size_t i = 0; i < mOtherGameList.size(); i++){ui::Layout * mItem = ui::Layout::create();mItem->setContentSize(Size(318, 110));mItem->setTouchEnabled(true);CGameKindItem *pGameKindItem = mOtherGameList[i];ControlButton *btnGame1 = createButton(stringFormatC("game_btn_nor_%d.png", pGameKindItem->m_GameKind.wKindID).c_str(),stringFormatC("game_btn_click_%d.png", pGameKindItem->m_GameKind.wKindID).c_str(),0, 0, this, cccontrol_selector(YYNewGameListLayer::onGameBtnClick));btnGame1->setPosition(Vec2(mItem->getContentSize().width / 2, mItem->getContentSize().height / 2));btnGame1->setTag(pGameKindItem->m_GameKind.wKindID);btnGame1->setEnabled(false);mItem->addChild(btnGame1);mItem->setTag(pGameKindItem->m_GameKind.wKindID);mOtherGameListView->pushBackCustomItem(mItem);}
阅读全文
0 0
- cocos2dx3.5 中listview item里面有ControlButton滑动失效的问题
- listView的item中有checkbox,导致setOnItemClick失效
- ListView的item中有button ImageButton CheckBox EditText等时 点击事件失效问题的解决
- ListView的item中有button ImageButton CheckBox EditText等时 点击事件失效问题的解决
- listview中item 有checkbox多选防止滑动 listview页面 出现checkbox错位问题
- Android ListView的Item点击失效问题
- ListView item点击事件和里面的控件冲突失效
- listview的item里面有Button,并给其设置了点击事件,而且有效可点击,但是listview的item点击事件却失效了
- android ListView中有checkbox后item点击事件失效
- ListView 与 它里面的Item 点击滑动冲突
- listview的条目中有button,或item点击失效的解决方案
- ListView中item的左右滑动
- ListView中item的左右滑动
- ListView的item中有Button,ImageButton之类的控件导导致item的点击事件失效
- ListView中Item有EditText,焦点问题
- ListView点击事件失效(item里面有button按钮控件)解决方法
- Listview中Item点击失效
- ListView中item点击失效
- Linux系统用户管理
- 2017国庆后有感
- Android 6.0 运行时权限管理最佳实践
- opencv2+ glob循环读入图片,将文件夹中的图片统一格式
- redis在java中的使用
- cocos2dx3.5 中listview item里面有ControlButton滑动失效的问题
- sql2000无法打开1433端口及解决方法
- SpringMVC学习笔记----
- 把 if-else 的代码风格改成表格驱动法的意义
- 关于搭建数据库的一些问题
- Docker 镜像优化与最佳实践
- 给窗体中控件绘图的几种方法
- python内置函数__init__及__str__的区别
- 输入一个数,输出其二进制数列。