Frage

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.

War es hilfreich?

Lösung 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;

Andere Tipps

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

You should use bounds instead of frame

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top