void WHScrollView::onTouchMoved(cocos2d::Touch *pTouch, cocos2d::Event *pEvent) { if (m_PointerId != pTouch->getID()) return; if (m_MoveCount < 8) m_MoveCount++; //CCScrollView::ccTouchMoved(pTouch, pEvent); if (!isVisible()) return; if (m_bScroll) { //if (_touches->containsObject(pTouch)) if (std::find(_touches.begin(), _touches.end(), pTouch) != _touches.end()) { if (_touches.size() == 1 && _dragging) { // scrolling CCPoint moveDistance, newPoint, maxInset, minInset; CCRect frame; float newX, newY; _touchMoved = true; CCPoint frameOriginal = getParent()->convertToWorldSpace(getPosition()); //frame = CCRectMake(frameOriginal.x, frameOriginal.y, m_tViewSize.width, m_tViewSize.height); frame = CCRectMake(0, 0, _viewSize.width, _viewSize.height); newPoint = convertTouchToNodeSpace((CCTouch*)_touches[0]); moveDistance = ccpSub(newPoint, _touchPoint); _touchPoint = newPoint; CCSize contentsize = getContentSize(); CCPoint offset = getContentOffset(); if (offset.y <= _viewSize.height - contentsize.height) { moveDistance.y = moveDistance.y / m_MoveCount; } //if (frame.containsPoint(convertToWorldSpace(newPoint))) if (frame.containsPoint(newPoint)) { switch (_direction) { case ScrollView::Direction::VERTICAL: moveDistance = ccp(0.0f, moveDistance.y); break; case ScrollView::Direction::HORIZONTAL: moveDistance = ccp(moveDistance.x, 0.0f); break; default: break; } _container->setPosition(ccpAdd(_container->getPosition(), moveDistance)); maxInset = _maxInset; minInset = _minInset; //check to see if offset lies within the inset bounds newX = MIN(_container->getPosition().x, maxInset.x); newX = MAX(newX, minInset.x); newY = MIN(_container->getPosition().y, maxInset.y); newY = MAX(newY, minInset.y); _scrollDistance = ccpSub(moveDistance, ccp(newX - _container->getPosition().x, newY - _container->getPosition().y)); setContentOffset(ccp(newX, newY)); } } else if (_touches.size() == 2 && !_dragging) { const float len = ccpDistance(_container->convertTouchToNodeSpace((CCTouch*)_touches[0]),_container->convertTouchToNodeSpace((CCTouch*)_touches[1])); setZoomScale(getZoomScale()*len / _touchLength); } } } for (int i = 0; i < m_TouchLayer.size(); i++) { if (m_TouchLayerTouched[i]) { CCLayer* pTouchLayer = m_TouchLayer[i]; pTouchLayer->ccTouchMoved(pTouch, pEvent); } } //CCScrollView::ccTouchMoved(pTouch, pEvent); }