0

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.

Reza_Rg
  • 3,345
  • 7
  • 32
  • 48
  • possible duplicate of [Using convertPoint to get the relative position inside a parent UIView](http://stackoverflow.com/questions/15883305/using-convertpoint-to-get-the-relative-position-inside-a-parent-uiview) – Cyrille Feb 17 '14 at 14:17

3 Answers3

2
CGPoint pointOfSubviewAccoringToSelfView = [self.view convertPoint:self.subview.frame.origin fromView:self.scrollView];
Basheer_CAD
  • 4,908
  • 24
  • 36
1

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;
Jeff Loughlin
  • 4,134
  • 2
  • 30
  • 47
0

You should use bounds instead of frame

Volker
  • 4,640
  • 1
  • 23
  • 31