swift when tableview scroll to top
swift when scroll to top
swift detect scroll to top
ios – Detecting the bottom "bounce" of UITableView – Stack Overflow
ios – Detect UIScrollview bottom reached – Stack Overflow
iphone – iOS : detect UIWebView reaching the top or bottom – Stack Overflow
iphone – UIScrollView, reaching the bottom of the scroll view – Stack Overflow
[整理]swift中列表中的scrollViewDidScrollToTop的作用和用法
但是也还是自己去试试:
我向上滚动到顶部后,执行顺序是:
1.两次scrollViewDidScroll
<code> func scrollViewDidScroll(scrollView: UIScrollView) { gLog.debug("scrollView=\(scrollView)") //scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -1.5}; contentSize: {320, 1578}> //scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -10}; contentSize: {320, 1578}> } </code>
2.一次scrollViewWillEndDragging
<code> func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) { gLog.debug("scrollView=\(scrollView), velocity=\(velocity), targetContentOffset=\(targetContentOffset)") //scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -10}; contentSize: {320, 1578}>, velocity=(0.0, -0.26938), targetContentOffset=0xbff08178 } </code>
3.一次scrollViewDidEndDragging
<code> func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) { gLog.debug("scrollView=\(scrollView), decelerate=\(decelerate)") //scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -10}; contentSize: {320, 1578}>, decelerate=true } </code>
4.一次scrollViewWillBeginDecelerating
<code> func scrollViewWillBeginDecelerating(scrollView: UIScrollView) { gLog.debug("scrollView=\(scrollView)") //scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -10}; contentSize: {320, 1578}> } </code>
5.再次scrollViewDidScroll
<code> func scrollViewDidScroll(scrollView: UIScrollView) { gLog.debug("scrollView=\(scrollView)") //scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -1.5}; contentSize: {320, 1578}> //scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -10}; contentSize: {320, 1578}> //scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, 0}; contentSize: {320, 1578}> } </code>
6.一次scrollViewDidEndDecelerating
<code> func scrollViewDidEndDecelerating(scrollView: UIScrollView) { gLog.debug("scrollView=\(scrollView)") //scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -0}; contentSize: {320, 1578}> } </code>
完整log如下:
<code>2016-04-16 10:17:32.356 [Debug] [main] [MessageTableViewController.swift:910] scrollViewDidScroll > scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -1.5}; contentSize: {320, 1578}> 2016-04-16 10:18:10.804 [Debug] [main] [MessageTableViewController.swift:910] scrollViewDidScroll > scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -10}; contentSize: {320, 1578}> 2016-04-16 10:18:22.657 [Debug] [main] [MessageTableViewController.swift:906] scrollViewWillEndDragging(_:withVelocity:targetContentOffset:) > scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -10}; contentSize: {320, 1578}>, velocity=(0.0, -0.26938), targetContentOffset=0xbff08178 2016-04-16 10:18:54.149 [Debug] [main] [MessageTableViewController.swift:898] scrollViewDidEndDragging(_:willDecelerate:) > scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -10}; contentSize: {320, 1578}>, decelerate=true 2016-04-16 10:20:20.922 [Debug] [main] [MessageTableViewController.swift:886] scrollViewWillBeginDecelerating > scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -10}; contentSize: {320, 1578}> 2016-04-16 10:20:58.607 [Debug] [main] [MessageTableViewController.swift:910] scrollViewDidScroll > scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, 0}; contentSize: {320, 1578}> 2016-04-16 10:21:33.192 [Debug] [main] [MessageTableViewController.swift:882] scrollViewDidEndDecelerating > scrollView=<UITableView: 0x7c338c00; frame = (0 0; 320 460); clipsToBounds = YES; autoresize = H+BM; gestureRecognizers = <NSArray: 0x7df70a80>; layer = <CALayer: 0x7df4fb00>; contentOffset: {0, -0}; contentSize: {320, 1578}> </code>
而别人的那个办法:
scrollViewDidScroll中判断scrollView.contentOffset.y小于0
虽然可以判断移动到顶部了
-》但是后执行多次
所以还是用那个:
scrollView.contentOffset.y == 0
去判断是否滚动到顶部了。
转载请注明:在路上 » [已解决]swift中检测列表滚动到顶部