NOrder
NOrder

Reputation: 2493

how to get the center point of a scrollview subview relative to scrollview superview?

I have a scollView(the blue one showing in the image below) containing 20 subviews(the white view).enter image description here

the superView of scrollView is called pView, for example, the the center point of white view1 relative to pView is (10,10), and the center point of view6 is (496,10), after I scroll this the view as following: enter image description here

the center point of view 6 is (10,10), but I don't know how to get it.

maybe I should use code like

        CGPoint centerPoint = [view6 convertPoint:view6.center toView:pView];

but I didn't get the right point

Upvotes: 1

Views: 881

Answers (1)

Aaron Golden
Aaron Golden

Reputation: 7102

view6.center is in the coordinate system of the superview of view6 (which is the UIScrollView). Try

CGPoint centerPoint = [scrollView convertPoint:view6.center toView:pView];

Upvotes: 3

Related Questions