iOS:如何在scrollView中确定对象的CGPoint

时间:2014-02-17 14:11:48

标签: ios objective-c uiview uiscrollview cgpoint

在UIView中,我可以得到像这样的对象的CGpoint:

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

但是当我的对象在scrollView中时我使用这段代码时,我和UIView中的x和y相同。那么当我在scrollView中时如何确定对象CGPoint。

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

添加UIScrollView的contentOffset。这将相对于UIScrollView中应用的滚动量调整您的点:

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

答案 2 :(得分:0)

您应该使用bounds代替frame