Search code examples
iphoneiosviewsubviews

Find the position of subview in a View


Goal : How we can find the position of subView in a View. I wants to find out the upper left (x,y)position of my scrollBar in a View, I am also using navigation Bar in my Application does it effect on the positioning of subViews from the Top?

I know how to find the height and width of subview like

CGSize viewSize = scrollView.frame.size;
height=viewSize.height;
width=viewSize.width;

Solution

  • What you're looking for is probably:

    CGPoint viewPosition = scrollView.frame.origin;
    x=viewPosition.x;
    y=viewPosition.y;
    

    But if you're looking to translate to another view's coordinate system, you could use:

    - (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view
    

    And pass it the point and view you wish to translate.