How can I find the x coordinate of the contentView that is equal to the center x of a UIScrollView's frame

136 Views Asked by At

I have a UIScrollView that scrolls horizontally. I have about 10 views lined up horizontally in that scrollview. I want to find the view that contains the center point of the scrollview's frame (not contentView.frame) as it scrolls. I am thinking to use the - (void)scrollViewDidScroll:(UIScrollView *)scrollView UIScrollView delegate method, but I am not sure how to find this.

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

You can get the start-point of a frame of a view (myChildView) in the reference of another view (scrollView) using the following code:

CGPoint origin = [myChildView convertPoint:CGPointMake(myChildView.bounds.origin.x, myChildView.bounds.origin.y) toView:[self scrollView]];

Use the scrollViewDidScroll: delegate method to pick your views and perform the calculations there.