The answer lies in
works in *OpenGL coordinates* (as opposed *window coordinates*) - values are relative to (left, bottom) with positive Y axis going upwards. Also, keep in mind the scroll view’s positioning and thecontainer
are anchored (CCNode::setAnchorPoint
) to (left, bottom).maxContainerOffset` returns (0, 0) and you’ve just tried to move to a positive content offset.
When you scroll down (move/pull the content upwards to see content below the cut/clip), you see the content below the bottom edge of the screen but it bounces back the moment you let go of the touch/drag because
The (attached) diagram shows the state of the scrollview and the container when they’re created/initialized. This is the state or the coordinates to”think in" when setting up and positioning the child elements and container. The gray rectangle (left, bottom) shows the valid region for scrolling the container. Imagine the container’s anchor point moves inside it.
To see the container scrolled to the top to begin with (what you’d expect when working in window coordinates), set the content offset accordingly (immediately after setting it up). This will give the expected results/behavior.
A more complete example is in the edited code below.
tallContentA = CCSprite::create;
CCSize winSize = CCDirector::sharedDirector~~>getWinSize;
CCLayer* scrollContainer = CCLayer::create; // Container for the scroll view
scrollContainer~~>setAnchorPoint; // CCScrollView does this too when it’s set as the container.
// Content for the container
CCSprite *tallContentB = CCSprite::create;
float scrollContainerHeight = tallContentA~~>getContentSize.height + tallContentB~~>getContentSize.height;
// Set up scroll view
scrollView = CCScrollView::create;
// ScrollView initializes at the . The container also gets positioned relative to that and goes Y-up.
// Pre-set it to the value CCScrollView::minContainerOffset will return when it’s scrolled to the top
scrollView~~>setContentOffset(ccp(0.f, (winSize.height-scrollContainerHeight*1.05f)), false);