Question

While in UIView I can get CGpoint of an object like this :

x = self.object.frame.origin.x;
y = self.object.frame.origin.y;

but when I use this code when my object is in scrollView, I got the same x and y as I am in UIView. so how can I determine object CGPoint when I am in scrollView.

Was it helpful?

Solution 2

Add the contentOffset of the UIScrollView. This will adjust your point relative to the amount of scroll applied in the UIScrollView:

x = self.object.bounds.origin.x + self.yourScrollView.contentOffset.x;
y = self.object.bounds.origin.y + self.yourScrollView.contentOffset.y;

OTHER TIPS

CGPoint pointOfSubviewAccoringToSelfView = [self.view convertPoint:self.subview.frame.origin fromView:self.scrollView];

You should use bounds instead of frame

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top