0

I have a vertical UIScrollView that has a StackView in which View Controllers are added to and each View Controller is of a different size.

If scrolling stopped at a specific View Controller (the 3rd one out of five View Controllers), I want to show a tooltip within it.

I already tried checking the scrollview content offset or the view controller's frame.origin.x position but this x position is always returned as 0

How do I know if this specific view controller is now visible to the user (scrollview stopped at it) in ScrollViewWillEndDragging?

Iva
  • 37
  • 7
  • You can find helpful info [here](https://stackoverflow.com/questions/868288/getting-the-visible-rect-of-an-uiscrollviews-content) – Ptit Xav Mar 20 '22 at 12:00

1 Answers1

0

Let's say you have 5 view controller and below are the heights.

V1 = 100
V2 = 200
V3 = 300
V4 = 400
V5 = 500

Now add a delegate for scrollview and keep an eye on scrollViewDidScroll

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    print("y position==\(scrollView.contentOffset.y)")
}

now based on scrollView.contentOffset.y, you can find out that which view controller is visible.

E.x.

For first

If scrollView.contentOffset.y <= 100, still first is going

For second

If scrollView.contentOffset.y >100 && scrollView.contentOffset.y <=(100+200), second one is visible

and so on

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276