How to stop scrolling animation of CCScrollView object in cocos2d v3

674 Views Asked by At

In my cocos2d v3 app for iOS I ran into misunderstanding of how to stop scrolling animation of CCScrollView object. I have tried some combinations of calls to its methods with no success, like

[_scrollView setScrollPosition:_scrollView.scrollPosition animated:NO];
[_scrollView stopAllActions];
[_dataListNode stopAllActions];

where _dataListNode is a ContentNode of CCScrollView

What is the correct way?

2

There are 2 best solutions below

1
On

The only way to stop scrolling animation which I have found by patching CCScrollView object

// reveal hidden velocity property
@property (nonatomic, assign) CGPoint velocity;
// this forces animation to stop
_scrollView.velocity = CGPointZero;

I am still searching for better way

0
On

CCScrollView which is ScrollView(cocos2d-x v3) has a method setContentOffsetInDuration So

svContent->setContentOffsetInDuration(svContent->getContentOffset(), 0.001f);

Would do the trick. Please be noticed that the duration - 0.001f is what I put as a small enough to see the animation almost instant.