Bug in CCScrollView zooming and setZoomScale()

Hi there,

I am referring to the most recent version of cocos2d-x (2.1.3).

I think there is a bug in CCScrollView. If you tap the scroll view with 2 fingers CCScrollView::ccTouchMoved() is called and the following code is being executed:

else if (m_pTouches->count() == 2 && !m_bDragging)
{
const float len = ccpDistance(m_pContainer->convertTouchToNodeSpace((CCTouch*)m_pTouches->objectAtIndex(0)), m_pContainer->convertTouchToNodeSpace((CCTouch*)m_pTouches->objectAtIndex(1)));
this->setZoomScale(this->getZoomScale()*len/m_fTouchLength);
}

So I assume that the view should be zoomed in when performing a pinch, right? Or what is the purpose of this?

However, in CCScrollView::setZoomScale() the following line does the scaling:
m_pContainer->setScale(MAX(m_fMinScale, MIN(m_fMaxScale, s)));

The problem is: m_fMinScale and m_fMaxScale are class members that are not accessible from the outside, and in initWithViewSize() they are set to 1.0f. They never change their value:
m_fMinScale = m_fMaxScale = 1.0f; (line 122)

This is an issue in our game because we scale down our instance of the Scroll View from the outside (let’s say the container’s scale factor is 0.8). If you then tap the view with 2 fingers the scroll view’s container is always scaled up to 1.0. And it can never scale down again.

Is this a bug? I would like to find a solution for this but I am not sure about the desired behavior of the Scroll View (why would you want to zoom into a scroll view anyway?), and the purpose of these class members m_fMinScale and m_fMaxScale if you cannot change their value.

I’d appreciate any response! Thanks in advance!

I could inherit from CCScrollView and add get/set routines for m_fMinScale and m_fMaxScale. This gave me the pinch-zoom functionality that I was looking for.

It would help if the CCScrollView class directly provided get/set functions for m_fMinScale and m_fMaxScale.

class ZoomView : public CCScrollView {
public:
static ZoomView* create(CCSize size, CCNode* container = NULL)
{
ZoomView* pRet = new ZoomView();
if (pRet && pRet~~>initWithViewSize)
{
pRet~~>autorelease();
}
else
{
CC_SAFE_DELETE(pRet);
}
return pRet;
}
void setMaxScale(float m) {
m_fMaxScale = m;
}
} *zoomView;

Hi @schngrg, I have tried to use the CCScrollView in extensions (v3.16 already have getters and setters). But when I zoom in/out something is messed up, and the boundaries of the content are incorrect…

Would you mind sharing a full example of how you use your ZoomView in the Scene? maybe I am setting up the wrong offset or something like that… thanks!