cocos2dx 让一个滚动层跟着另一个动

m_trendList = getUIListByName("trendList");
	m_trendList->addEventListenerScrollView(this, SEL_ScrollViewEvent(&NNBoard::listScrollEvent));
	m_trendList->addTouchEventListener(this, SEL_TouchEvent(&NNBoard::listTouchEvent));
	for (int i = 0; i < 80; i++)
	{
		UIImageView *_ui = UIImageView::create();
		_ui->loadTexture("LunPan/circlered");
		m_trendList->pushBackCustomItem(_ui);
	}
	m_eoList = getUIListByName("eoList");
	m_eoList->addEventListenerScrollView(this, SEL_ScrollViewEvent(&NNBoard::listScrollEvent));
	m_eoList->addTouchEventListener(this, SEL_TouchEvent(&NNBoard::listTouchEvent));
	for (int i = 0; i < 80; i++)
	{
		UIImageView *_ui = UIImageView::create();
		_ui->loadTexture("LunPan/circlered");
		m_eoList->pushBackCustomItem(_ui);
	}
	m_sizeList = getUIListByName("sizeList");
	m_sizeList->addEventListenerScrollView(this, SEL_ScrollViewEvent(&NNBoard::listScrollEvent));
	m_sizeList->addTouchEventListener(this, SEL_TouchEvent(&NNBoard::listTouchEvent));
	for (int i = 0; i < 80; i++)
	{
		UIImageView *_ui = UIImageView::create();
		_ui->loadTexture("LunPan/circlered");
		m_sizeList->pushBackCustomItem(_ui);
	}
	m_colorList = getUIListByName("colorList");
	m_colorList->addEventListenerScrollView(this, SEL_ScrollViewEvent(&NNBoard::listScrollEvent));
	m_colorList->addTouchEventListener(this, SEL_TouchEvent(&NNBoard::listTouchEvent));
	for (int i = 0; i < 80; i++)
	{
		UIImageView *_ui = UIImageView::create();
		_ui->loadTexture("LunPan/circlered");
		m_colorList->pushBackCustomItem(_ui);
	}

void NNBoard::listScrollEvent( CCObject* obj,ScrollviewEventType type )
{
	switch (type)
	{
	case SCROLLVIEW_EVENT_SCROLLING:
		UIListView* _ui = (UIListView*)obj;
		CCPoint _point = (_ui)->getInnerContainer()->getPosition();
		if (m_currentTouchList == _ui)
		{
			if (_ui == m_trendList)
			{
				m_eoList->scrollToDestination(_point,0.25);
				m_sizeList->scrollToDestination(_point,0.5);
				m_colorList->scrollToDestination(_point,0.75);
			}
			else if(_ui == m_eoList)
			{
				m_trendList->scrollToDestination(_point,0.25);
				m_sizeList->scrollToDestination(_point,0.25);
				m_colorList->scrollToDestination(_point,0.5);
			}
			else if(_ui == m_sizeList)
			{
				m_trendList->scrollToDestination(_point,0.5);
				m_eoList->scrollToDestination(_point,0.25);
				m_colorList->scrollToDestination(_point,0.25);
			}
			else
			{
				m_sizeList->scrollToDestination(_point,0.25);
				m_eoList->scrollToDestination(_point,0.5);
				m_trendList->scrollToDestination(_point,0.75);
			}
		}
		
		break;
	}
	
}

void NNBoard::listTouchEvent( CCObject* obj,TouchEventType type )
{
	m_currentTouchList = (UIListView*)(obj);
}

你可能感兴趣的:(cocos2dx 让一个滚动层跟着另一个动)