342 Size widgetSize =
_widget->getContentSize();
351 Text* alert = Text::create(
"ScrollView scroll to percent both direction bounce",
"fonts/Marker Felt.ttf",20);
352 alert->setColor(Color3B(159, 168, 176));
353 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 4.5));
356 Layout* root =
static_cast<Layout*
>(
_uiLayer->getChildByTag(81));
358 Layout* background =
dynamic_cast<Layout*
>(root->getChildByName(
"background_Panel"));
360 ui::ScrollView* sc = ui::ScrollView::create();
361 sc->setBackGroundColor(Color3B::GREEN);
362 sc->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
363 sc->setBounceEnabled(
true);
364 sc->setDirection(ui::ScrollView::Direction::BOTH);
365 sc->setInnerContainerSize(Size(480.0f, 320.0f));
366 sc->setContentSize(Size(100.0f,100.0f));
367 sc->setScrollBarPositionFromCornerForHorizontal(Vec2(5.0f, sc->getContentSize().height - 5));
368 sc->setScrollBarPositionFromCornerForVertical(Vec2(sc->getContentSize().width - 5, 5.0f));
369 sc->setScrollBarAutoHideEnabled(
false);
370 Size backgroundSize = background->getContentSize();
371 sc->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
372 (backgroundSize.width - sc->getContentSize().width) / 2.0f,
373 (widgetSize.height - backgroundSize.height) / 2.0f +
374 (backgroundSize.height - sc->getContentSize().height) / 2.0f));
375 sc->scrollToPercentBothDirection(Vec2(50.0f, 50.0f), 1,
true);
376 ImageView* iv = ImageView::create(
"cocosui/Hello.png");
377 iv->setPosition(Vec2(240.0f, 160.0f));
cocos2d::Layer * _uiLayer
virtual bool init() override
cocos2d::ui::Layout * _widget