문제

I have scrollView in which there are 12 buttons. On window only four buttons are visible at a time. For animation purpose I need button's position regarding to the window.

I had followed these methods but its not working for me:

[btn.superview convertPoint:btn.frame.origin toView:nil];

btnImgeView.frame= CGRectMake(btn.frame.origin.x + 10, 240, btn.frame.size.width, btn.frame.size.height);

btn.frame.origin.x is taking coordinate from scrollView's origin not from the origin of the screen.

how can I get the button's position regarding to the window?

도움이 되었습니까?

해결책

From your description it sounds like what you really want to do is display an image view where an button appears, but its location is inside a scroll view.

As suspected, calculating screen coordinates is not the correct approach here. Instead, you need to offset the button's rect/origin with the scroll view's displacement to determine the correct position.

Use the scroll view's -contentOffset property to get a CGPoint indicating the, well, offset of the content. Subtract that point from the button's bounds origin (or just center if you would like something more convenient). That will give you the correct point at which to display your image (relative to the scroll view's frame origin).

If you aren't displaying the image in the scroll view, you can transform the point to the superview's coordinate system with -[UIView convertPoint:fromView:] or [UIView convertPoint:toView:].

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