bool HelloCocosNasScene::init() { if (!NASView::init()) { return false; } CCSize sizeW = CCDirector::sharedDirector()->getWinSize(); NASScrollView *vScroll = NASScrollView::create(); vScroll->setTag(TagScroll); vScroll->setContentSize(sizeW); vScroll->m_pScrollee->setContentSize(CCSizeMake(sizeW.width*PAGE_NUM, sizeW.height)); vScroll->m_bBounceY = false; vScroll->m_bPaging = true; vScroll->m_pDelegate = this; this->addChild(vScroll); float dx = (sizeW.width-ICON_SIZE*4)/5.0f; for (int i = 0; i < PAGE_NUM; i++) { const static int page[PAGE_NUM] = {ICON_NUM_PAGE_0, ICON_NUM_PAGE_1, ICON_NUM_PAGE_2}; for (int j = 0; j < page[i]; j++) { char filename[16]; sprintf(filename, "icon_%02d_%02d.png", i, j); NASButtonView *buttonIcon = NASButtonView::create(filename, this); buttonIcon->setTag(i*100+j); int row = j/4; int vertical = j%4; float x = i*sizeW.width + dx*(vertical+1)+ICON_SIZE*vertical + 5.0f; float y = sizeW.height-(ICON_VERTICAL_SPACE+ICON_SIZE)*(row+1); buttonIcon->setPosition(CCPointMake(x, y)); vScroll->m_pScrollee->addChild(buttonIcon); } } return true; } void HelloCocosNasScene::buttonEvent(NASButtonView* button, NASButtonViewEvent event, CCTouch* touch) { if (event == NASButtonViewEventTouchUpInside) { } } void HelloCocosNasScene::nasScrollViewDidScroll(NASScrollView* pScroll) { } void HelloCocosNasScene::nasScrollViewDidMotion(NASScrollView* pScroll) { }
bool HelloCocosNasScene::init() { if ( !NASView::init() ) { return false; } auto sizeW = Director::getInstance()->getWinSize(); auto vScroll = NASScrollView::create(); vScroll->setTag(TagScroll); vScroll->setContentSize(sizeW); vScroll->m_pScrollee->setContentSize(Size(sizeW.width*PAGE_NUM, sizeW.height)); vScroll->m_bBounceX = true; vScroll->m_bPaging = true; this->addChild(vScroll); auto dx = (sizeW.width-ICON_SIZE*4)/5.0f; for (auto i = 0; i < PAGE_NUM; i++) { const static int page[PAGE_NUM] = {ICON_NUM_PAGE_0, ICON_NUM_PAGE_1, ICON_NUM_PAGE_2}; for (auto j = 0; j < page[i]; j++) { char filename[16]; sprintf(filename, "icon_%02d_%02d.png", i, j); auto buttonIcon = NASButtonView::create(filename, nullptr); auto row = j/4; auto vertical = j%4; auto x = i*sizeW.width + dx*(vertical+1)+ICON_SIZE*vertical + 5.0f; auto y = sizeW.height-STATUSBAR_HEIGHT-(ICON_VERTICAL_SPACE+ICON_SIZE)*(row+1); buttonIcon->setPosition(Vec2(x, y)); vScroll->m_pScrollee->addChild(buttonIcon); buttonIcon->onTouchUpInside = [i, j](NASButtonView *button, Touch *touch) { // on button }; } } vScroll->onDidScroll = [](NASScrollView *pScroll) { // did scroll }; vScroll->onDidMotion = [](NASScrollView *pScroll) { // did motion }; return true; }
init: function () { this._super(); var c_nPage = 3; var c_aPage = [14, 4, 2]; var c_nIconSize = 70; var c_nIconVerticalSpace = 20; var size = cc.winSize; this.scroll = NASScrollView.create(); this.scroll.attr({ x: 0, width: size.width, height: size.height, m_bBounceY: false, m_bPaging: true }); this.scroll.m_pScrollee.setContentSize(cc.size((size.width) * 3, size.height)); this.addChild(this.scroll); var dx = (size.width - c_nIconSize * 4) / 5.0; for (var i = 0; i < c_nPage; i++) { for (var j = 0; j < c_aPage[i]; j++) { var filename = "res/icon_" + ("0" + i).slice(-2) + "_" + ("0" + j).slice(-2) + ".png"; var button = NASButtonView.create(filename, null); var row = Math.floor(j/4); var vertical = j%4; var x = i*size.width + dx*(vertical+1) + c_nIconSize*vertical + 5; var y = size.height - (c_nIconVerticalSpace+c_nIconSize)*(row+1); button.attr({ x: x, y: y }); button.m_fOnTouchUpInside = NASButtonViewEvent.create(function (button, touch) { // on button }); this.scroll.m_pScrollee.addChild(button); } } this.scroll.m_fOnDidScroll = NASScrollViewEvent.create(function (scroll) { // did scroll }); this.scroll.m_fOnDidMotion = NASScrollViewEvent.create(function (scroll) { // did motion }); return true; }