문제

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.

도움이 되었습니까?

해결책 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;

다른 팁

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

You should use bounds instead of frame

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top