有没有一种方法可以知道动画何时结束并且uiscrollview已经停止滚动。
我这样做是因为有时对我来说使用委托并不实际,比如在UIViewController转换中进行此操作:
[UIView animateWithDuration:0.3 animations:^{
[scrollView setContentOffset:CGPointMake(0, -scrollView.contentInset.top) animated:NO];
} completion:^(BOOL finished) {
// This is called when it's complete
}];
为您的UIScrollView实现UIScrollViewDelegate代理方法:
使用scrollViewDidEndScrollingAnimation:
来检测滚动动画何时结束,当您通过调用setContentOffset:animated:
或scrollRectToVisible:animated:
方法(使用animated:YES)启动滚动时。
如果您想要监控由触摸手势引起的滚动视图运动,请使用scrollViewDidEndDecelerating:
方法,在滚动运动停止时调用。
// do note that you need all three of the following
public func scrollViewDidEndScrollingAnimation(_ s: UIScrollView) {
// covers case setContentOffset/scrollRectToVisible
fingerOrProgrammaticMoveDone()
}
public func scrollViewDidEndDragging(_ s: UIScrollView, willDecelerate d: Bool) {
if decelerate == false {
// covers certain cases of user finger
fingerOrProgrammaticMoveDone()
}
}
public func scrollViewDidEndDecelerating(_ s: UIScrollView) {
// covers certain cases of user finger
fingerOrProgrammaticMoveDone()
}
在中间的那个语句里,要小心不要忘记额外的“if”从句。
然后在 fingerOrProgrammaticMoveDone()
中执行你需要的操作。
处理分页滚动的恶梦是一个很好的例子。非常非常难以知道你在哪一页。
scrollViewDidEndDecelerating:
是 UIScrollView 的代理方法,当 scrollView 完全停止时会被调用。