1、//滚动层背景图
auto layoutSp = Sprite::create("RankingBg@2x.png");
layoutSp->setPosition(_screenWidth/2,_screenHeight/2);
this->addChild(layoutSp);
2、//创建滚动层的大小
Size backgroundSize = layoutSp->getContentSize();
3、//创建一个ScrollView滚动层容器
auto scrollView = ScrollView::create();
//激活反弹,拉过了之后,可以弹回来
scrollView->setBounceEnabled(true);
//设置锚点
//设置滚动方向垂直滚动
scrollView->setDirection(ScrollView::Direction::VERTICAL);
//设置滚动层的大小
scrollView->setContentSize(Size(backgroundSize.width,backgroundSize.height-20));//外部窗口大小
//设置滚动层的坐标
scrollView->setPosition(Vec2((_screenWidth - backgroundSize.width)/2 +
(backgroundSize.width - scrollView->getContentSize().width)/2,
(_screenHeight - backgroundSize.height)/2 +
(backgroundSize.height - scrollView->getContentSize().height)/2));//为滚动层左下角的坐标
this->addChild(scrollView);
4、//设置内部框大小
float innerWidth = scrollView->getContentSize().width;
float innerHeight = 200;
scrollView->setInnerContainerSize(Size(innerWidth,innerHeight));