Merge pull request #14940 from mxenabled/stop_auto_scroll

Add ability to stop auto scrolling in ui::ScrollView and extension::ScrollView
This commit is contained in:
zilongshanren 2016-02-01 14:27:55 +08:00
commit ee31d2ad22
4 changed files with 44 additions and 12 deletions

View File

@ -469,6 +469,14 @@ void ScrollView::startAutoScroll(const Vec2& deltaMove, float timeInSec, bool at
}
}
void ScrollView::stopAutoScroll()
{
_autoScrolling = false;
_autoScrollAttenuate = true;
_autoScrollTotalTime = 0;
_autoScrollAccumulatedTime = 0;
}
bool ScrollView::isNecessaryAutoScrollBrake()
{
if(_autoScrollBraking)

View File

@ -156,61 +156,66 @@ public:
*/
Layout* getInnerContainer()const;
/**
* Immediately stops inner container scroll initiated by any of the "scrollTo*" member functions
*/
virtual void stopAutoScroll();
/**
* Scroll inner container to bottom boundary of scrollview.
* @param timeInSec Time in seconds.
* @param attenuated Whether scroll speed attenuate or not.
*/
void scrollToBottom(float timeInSec, bool attenuated);
virtual void scrollToBottom(float timeInSec, bool attenuated);
/**
* Scroll inner container to top boundary of scrollview.
* @param timeInSec Time in seconds.
* @param attenuated Whether scroll speed attenuate or not.
*/
void scrollToTop(float timeInSec, bool attenuated);
virtual void scrollToTop(float timeInSec, bool attenuated);
/**
* Scroll inner container to left boundary of scrollview.
* @param timeInSec Time in seconds.
* @param attenuated Whether scroll speed attenuate or not.
*/
void scrollToLeft(float timeInSec, bool attenuated);
virtual void scrollToLeft(float timeInSec, bool attenuated);
/**
* Scroll inner container to right boundary of scrollview.
* @param timeInSec Time in seconds.
* @param attenuated Whether scroll speed attenuate or not.
*/
void scrollToRight(float timeInSec, bool attenuated);
virtual void scrollToRight(float timeInSec, bool attenuated);
/**
* Scroll inner container to top and left boundary of scrollview.
* @param timeInSec Time in seconds.
* @param attenuated Whether scroll speed attenuate or not.
*/
void scrollToTopLeft(float timeInSec, bool attenuated);
virtual void scrollToTopLeft(float timeInSec, bool attenuated);
/**
* Scroll inner container to top and right boundary of scrollview.
* @param timeInSec Time in seconds.
* @param attenuated Whether scroll speed attenuate or not.
*/
void scrollToTopRight(float timeInSec, bool attenuated);
virtual void scrollToTopRight(float timeInSec, bool attenuated);
/**
* Scroll inner container to bottom and left boundary of scrollview.
* @param timeInSec Time in seconds.
* @param attenuated Whether scroll speed attenuate or not.
*/
void scrollToBottomLeft(float timeInSec, bool attenuated);
virtual void scrollToBottomLeft(float timeInSec, bool attenuated);
/**
* Scroll inner container to bottom and right boundary of scrollview.
* @param timeInSec Time in seconds
* @param attenuated Whether scroll speed attenuate or not.
*/
void scrollToBottomRight(float timeInSec, bool attenuated);
virtual void scrollToBottomRight(float timeInSec, bool attenuated);
/**
* Scroll inner container to vertical percent position of scrollview.
@ -218,7 +223,7 @@ public:
* @param timeInSec Time in seconds.
* @param attenuated Whether scroll speed attenuate or not.
*/
void scrollToPercentVertical(float percent, float timeInSec, bool attenuated);
virtual void scrollToPercentVertical(float percent, float timeInSec, bool attenuated);
/**
* Scroll inner container to horizontal percent position of scrollview.
@ -226,7 +231,7 @@ public:
* @param timeInSec Time in seconds.
* @param attenuated Whether scroll speed attenuate or not.
*/
void scrollToPercentHorizontal(float percent, float timeInSec, bool attenuated);
virtual void scrollToPercentHorizontal(float percent, float timeInSec, bool attenuated);
/**
* Scroll inner container to both direction percent position of scrollview.
@ -234,7 +239,7 @@ public:
* @param timeInSec Time in seconds.
* @param attenuated Whether scroll speed attenuate or not.
*/
void scrollToPercentBothDirection(const Vec2& percent, float timeInSec, bool attenuated);
virtual void scrollToPercentBothDirection(const Vec2& percent, float timeInSec, bool attenuated);
/**
* Move inner container to bottom boundary of scrollview.

View File

@ -64,6 +64,7 @@ ScrollView::ScrollView()
, _maxScale(0.0f)
, _scissorRestored(false)
, _touchListener(nullptr)
, _animatedScrollAction(nullptr)
{
}
@ -234,12 +235,21 @@ void ScrollView::setContentOffsetInDuration(Vec2 offset, float dt)
{
FiniteTimeAction *scroll, *expire;
if (_animatedScrollAction) {
stopAnimatedContentOffset();
}
scroll = MoveTo::create(dt, offset);
expire = CallFuncN::create(CC_CALLBACK_1(ScrollView::stoppedAnimatedScroll,this));
_container->runAction(Sequence::create(scroll, expire, nullptr));
_animatedScrollAction = _container->runAction(Sequence::create(scroll, expire, nullptr));
this->schedule(CC_SCHEDULE_SELECTOR(ScrollView::performedAnimatedScroll));
}
void ScrollView::stopAnimatedContentOffset() {
stopAction(_animatedScrollAction);
_animatedScrollAction = nullptr;
stoppedAnimatedScroll(this);
}
Vec2 ScrollView::getContentOffset()
{
return _container->getPosition();

View File

@ -128,6 +128,10 @@ public:
* @param dt The animation duration.
*/
void setContentOffsetInDuration(Vec2 offset, float dt);
/**
* Halts the movement animation of the inner content started with setContentOffset() or setContentOffsetInDuration()
*/
void stopAnimatedContentOffset();
void setZoomScale(float s);
/**
@ -378,6 +382,11 @@ protected:
CustomCommand _beforeDrawCommand;
CustomCommand _afterDrawCommand;
/**
* Action created with setContentOffsetInDuration(), saved so it can be halted
*/
Action* _animatedScrollAction;
};