在UIView中,我可以得到像这样的对象的CGpoint:
x = self.object.frame.origin.x;
y = self.object.frame.origin.y;
但是当我的对象在scrollView中时我使用这段代码时,我和UIView中的x和y相同。那么当我在scrollView中时如何确定对象CGPoint。
答案 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