【发布时间】:2012-02-26 18:14:00
【问题描述】:
有没有办法知道动画何时结束,uiscrollview 何时停止。
【问题讨论】:
-
关于这个非常古老的问题,现在有三种情况必须涵盖。这是 iOS 中最奇怪和最困难的问题之一。 ://
标签: ios uiscrollview uiscrollviewdelegate
有没有办法知道动画何时结束,uiscrollview 何时停止。
【问题讨论】:
标签: ios uiscrollview uiscrollviewdelegate
scrollViewDidEndDecelerating:在scrollView完全停止时调用UIScrollView委托方法。
【讨论】:
【讨论】:
通过以下方式为您的 UIScrollView 实现 UIScrollViewDelegate 委托方法:
当您通过调用setContentOffset:animated: 或scrollRectToVisible:animated: 方法(使用动画:YES)启动滚动时,使用scrollViewDidEndScrollingAnimation: 检测滚动动画何时结束。
如果要监视由触摸手势启动的滚动视图运动,请使用scrollViewDidEndDecelerating: 方法,该方法在滚动运动停止时调用。
【讨论】:
我这样做是因为有时使用委托对我来说并不实用,比如我在 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
}];
【讨论】:
completion,但我的animation 和completion 正在逐行执行。没有按预期工作:(
// 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() 中,做你需要的。
处理分页滚动的噩梦就是一个很好的例子。很难知道你在哪个页面。
【讨论】: