724 Size widgetSize =
_widget->getContentSize();
733 Text* alert = Text::create(
"ScrollView events",
"fonts/Marker Felt.ttf",30);
734 alert->setColor(Color3B(159, 168, 176));
735 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
738 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
740 Layout* background =
static_cast<Layout*
>(root->getChildByName(
"background_Panel"));
743 ui::ScrollView* scrollView = ui::ScrollView::create();
744 scrollView->setDirection(ui::ScrollView::Direction::BOTH);
745 scrollView->setTouchEnabled(
true);
746 scrollView->setBounceEnabled(
true);
747 scrollView->setBackGroundImageScale9Enabled(
true);
748 scrollView->setBackGroundImage(
"cocosui/green_edit.png");
749 scrollView->setContentSize(Size(210, 122.5));
750 scrollView->setScrollBarWidth(4);
751 scrollView->setScrollBarPositionFromCorner(Vec2(6, 6));
752 Size backgroundSize = background->getContentSize();
753 scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
754 (backgroundSize.width - scrollView->getContentSize().width) / 2.0f,
755 (widgetSize.height - backgroundSize.height) / 2.0f +
756 (backgroundSize.height - scrollView->getContentSize().height) / 2.0f));
757 ImageView* imageView = ImageView::create(
"Hello.png");
758 scrollView->addChild(imageView);
760 scrollView->setInnerContainerSize(imageView->getContentSize());
761 Size innerSize = scrollView->getInnerContainerSize();
762 imageView->setPosition(Vec2(innerSize.width / 2.0f, innerSize.height / 2.0f));
767 scrollView->jumpToBottomRight();
769 auto getRandomColor = [] {
770 return Color4B(random(0, 255), random(0, 255), random(0, 255), 255);
772 scrollView->addEventListener([&](Ref*, ui::ScrollView::EventType e) {
774 case ui::ScrollView::EventType::SCROLLING_BEGAN:
778 case ui::ScrollView::EventType::SCROLLING_ENDED:
cocos2d::Layer * _uiLayer
virtual bool init() override
cocos2d::ui::Layout * _widget