PageView 和 Button混合使用的问题

PageView 和 Button混合使用的问题

PageView中存着 ui::BUtton 然后 我把PageView->setTouchEnable(false);

可是 不起作用 我想禁止 掉这个 触摸改用 123…按钮切换背包页面

然后我再试了 不用ui::Button 用Sprite 就 可以禁止掉这个触摸 PageView->setTouchEnable(false);

:12:

:2::13:

关注,一会试试看

PageView和Button有各自的分发事件,你设置PageView的touchEnable为false是不会影响到Button得,只是PageView不能拖动了。
你必须自己手动再去设置下Button的。

:8:
没明白 我的意思。。。
我说的是 我把 PageView->setTouchEnable(false); PageView 还能拉动 (在使用ui::Button)的情况出现

对了 网上下载的素材 没有提供图片的pos位置 。。。不知如何使用:12:

有什么办法 分割图片出来 。。。:12: 虽然感觉很不现实。。。:12:

我是不知道有什么分割的办法…应该是没…然后你可以试试TestCpp里面,有个现成的加了Button得例子。在UIPageViewTest.cpp里,有个PageView with Buttons(你直接搜这个)加下setTouchEnable(false)试试看…

我试过是可以的…

:10: :10: :10: 显然没有办法。。。

其实你要是会点PS的话…可以慢慢抠出来…:13:我当初就这么干过:15::15:抠的死去活来的…爽爽的…

:12::12::12:

bool UIPageViewButtonTest::init()
{
    if (UIScene::init())
    {
        Size widgetSize = _widget->getContentSize();
        
        // Add a label in which the dragpanel events will be displayed
        _displayValueLabel = Text::create("Move by horizontal direction", "fonts/Marker Felt.ttf", 32);
        _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
        _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
                                             widgetSize.height / 2.0f +
                                             _displayValueLabel->getContentSize().height * 1.5));
        _uiLayer->addChild(_displayValueLabel);
        
        // Add the black background
        Text* alert = Text::create("PageView with Buttons", "fonts/Marker Felt.ttf", 30);
        alert->setColor(Color3B(159, 168, 176));
        alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
        _uiLayer->addChild(alert);
        
        Layout* root = static_cast(_uiLayer->getChildByTag(81));
        
        Layout* background = dynamic_cast(root->getChildByName("background_Panel"));
        
        // Create the page view
        PageView* pageView = PageView::create();
        pageView->setContentSize(Size(240.0f, 130.0f));
        Size backgroundSize = background->getContentSize();
        pageView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
                                   (backgroundSize.width - pageView->getContentSize().width) / 2.0f,
                                   (widgetSize.height - backgroundSize.height) / 2.0f +
                                   (backgroundSize.height - pageView->getContentSize().height) / 2.0f));
        
        pageView->removeAllPages();
        
        int pageCount = 4;
        for (int i = 0; i < pageCount; ++i)
        {
            HBox* outerBox = HBox::create();
            outerBox->setContentSize(Size(240.0f, 130.0f));

            for (int k = 0; k < 2; ++k) {
                VBox* innerBox = VBox::create();
                
                for (int j = 0; j < 3; j++) {
                    Button *btn = Button::create("cocosui/animationbuttonnormal.png",
                                                 "cocosui/animationbuttonpressed.png");
                    btn->setName(StringUtils::format("button %d", j));
                    btn->addTouchEventListener( CC_CALLBACK_2(UIPageViewButtonTest::onButtonClicked, this));
                    
                    innerBox->addChild(btn);
                }
                
                LinearLayoutParameter *parameter = LinearLayoutParameter::create();
                parameter->setMargin(Margin(0,0,100,0));
                innerBox->setLayoutParameter(parameter);
                
                outerBox->addChild(innerBox);

            }
            
            pageView->insertPage(outerBox,i);
        }
        
        pageView->removePageAtIndex(0);
        
        pageView->addEventListener(CC_CALLBACK_2(UIPageViewButtonTest::pageViewEvent, this));
        
        pageView->setTouchEnabled(false);//*----*----- 这个 是屏蔽PageView 的触摸  你试试  我这里 设置了false 了 还是一样可以拉动 是 cpptest中的
        
        _uiLayer->addChild(pageView);
        
        return true;
    }
    return false;
}


```

楼主用的时哪个版本?我是在3.4Final里弄得…我也是这么加的…没问题…你说下版本,我试试看

:8: 我也扣过一次。。。= =弄了一个小时就扣了几张图片出来 。

3.3rc2

我这边试了3.3Final版本,是不能拉的…rc不是正式版,不稳定的,建议楼主换Final…类似3.4的非正式版,已经只放在论坛上,官网上不再提供下载…你先试试3.3Final或者3.4吧…

好吧…我知道楼主是什么拉的了…你是按着按钮拉的:12::12::12:是不是Bug一会给楼答案…

确认是引擎Bug,后续版本会修复…楼主好厉害= =!经常发现Bug:12::12:,不去做测试可惜了…感谢楼主反馈哈…

:8: …= =测试那么累:12:还是编程好点。

void PageView::checkChildInfo(int handleState,Widget* sender, const CCPoint &touchPoint)
{
if(this->isTouchEnabled())
{
interceptTouchEvent(handleState, sender, touchPoint);
}
}

只有PageView可触发触摸事件的时候,才处理页面上子控件向父控件传递的事件,不可触摸的时候,不处理传递过来的事件。

:14: 学了unity3d 后 找到办法 了。。。有个工具叫 PngSplit 开源的 可以自动 识别切出。。。