ios – 如何检测UIScrollView何时完成滚动在Swift中

前端之家收集整理的这篇文章主要介绍了ios – 如何检测UIScrollView何时完成滚动在Swift中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
无论如何,Ashley Smart( How to detect when a UIScrollView has finished scrolling)提出的Obj-C中的这个问题是一个很好的解决方案.
-(void)scrollViewDidScroll:(UIScrollView *)sender 
{   
[NSObject cancelPrevIoUsPerformRequestsWithTarget:self];
    //ensure that the end of scroll is fired.
    [self performSelector:@selector(scrollViewDidEndScrollingAnimation:) withObject:nil afterDelay:0.3]; 

...
}

-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
    [NSObject cancelPrevIoUsPerformRequestsWithTarget:self];
...
}

但是,我需要一个解决方案,在Swift中.

似乎Matt(dispatch_after – GCD in swift?)提供的优秀延迟功能可能会有所帮助.

func delay(delay:Double,closure:()->()) {
    dispatch_after(
        dispatch_time(
            DISPATCH_TIME_NOW,Int64(delay * Double(NSEC_PER_SEC))
        ),dispatch_get_main_queue(),closure)
}

并实施为……

delay(0.4) {
    // do stuff
}

但我还是没把它放在一起.有帮助吗?

解决方法

委托方法告诉您何时完成
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
    println("Scroll finished")
}
原文链接:https://www.f2er.com/iOS/333360.html

猜你在找的iOS相关文章