Sometimes need to use ScrollView but do not want to have that annoying elastic effect, naturally think of setbounds (false), but after the practice will find that the function of sliding inertia also to cancel, so that is how much you slip, how much scrolling, user experience is very poor ...
Solving this method is simple:
1. Inheriting scrollviewdelegate
2. Implementing Virtual Functions
virtual void scrollViewDidScroll(ScrollView* view);
The function is then implemented as follows
void EquipShopItemLayer::scrollViewDidScroll(ScrollView* view){ auto layout = view -> getContainer(); float currentY = layout -> getPositionY(); if (currentY > 0) { view -> setContentOffset(Vec2(0, 0)); } if (-currentY > layout -> getContentSize().height - view -> getViewSize().height) { view -> setContentOffset(Vec2(0, -layout -> getContentSize().height + view -> getViewSize().height)); }}
欢迎访问我的博客:helkyle.tk
COCOS2DX ScrollView does not affect sliding, remove elasticity tips