0

Is there a function to check what way the table view is scrolled? up/down.

I have an uiView that I need to hide depending on what way is scrolled.

I also have my table view inside an container view.

Thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Kiwo Tew
  • 1,491
  • 1
  • 22
  • 39
  • set a delegate for `UIScrollview` or if that is accurate enough you can check it in the `–tableView:cellForRowAtIndexPath:` every time when you need to present a new cell (obviously because of scrolling) – it depends on what you really need. – holex Aug 06 '15 at 14:12
  • @holex Thanks it kinda works. But since scroll views has that bounce effect it fires both functions "didScrollUp" and "didScrollDown" back and forth a few times if I scroll all the way to the top or if I do a "pull to refresh" This results in my view toggeling between hidden/shown a few times. So maby I am off adding a swipe gesture to the scrollview/table view? – Kiwo Tew Aug 06 '15 at 14:28
  • @KiwoTew, if you use delegates of `UIScrollView` you may need to check whether the current offset is outside of the content's size, so you can pretty much detect when the bouncing starts, and can prevent the currently unwanted method calls. – holex Aug 06 '15 at 15:19

2 Answers2

2

Use UIScrollViewDelegate and

func scrollViewDidScroll(_ scrollView: UIScrollView)

method

rshev
  • 4,086
  • 1
  • 23
  • 32
  • Thanks it kinda works. But since scroll views has that bounce effect it fires both functions "didScrollUp" and "didScrollDown" back and forth a few times if I scroll all the way to the top or if I do a "pull to refresh" This results in my view toggeling between hidden/shown a few times. So maby I am off adding a swipe gesture to the scrollview/table view? – Kiwo Tew Aug 06 '15 at 14:28
  • Try to ignore negative `contentOffset`s – rshev Aug 06 '15 at 14:32
  • @KiwoTew please accept the answer if I helped you. – rshev Aug 19 '15 at 15:57
0

UITableViewDelegate is inherited from UIScrollViewDelegate, so you can implement this method

func scrollViewDidScroll(scrollView: UIScrollView) // any offset changes
hash3r
  • 411
  • 6
  • 16