Search code examples
iphoneuiviewcoordinate-transformation

Getting Co-ordinates of inner view corresponding to outer view


My view controller has following hierarchy:

Month view -> Scroll View -> Calendar View -> Grid View -> Container View -> Tile view.

When user clicks the button which is placed in the Tile view, the new view should get added on MonthView -> Scroll View with X-Coordinate same as that of Container View.

I have tried following function :

CGRect tranformRect = [Container View convertRect:Container_View_Frame toView:Month view -> Scroll View]

But the X-Coordinate which I get is not which I required. Does I m doing any thing wrong? Attached are screen shots :

Initial Image

Invalid

Valid

Thanx in advance.


Solution

  • It looks like you are misunderstanding what the frame rect is. The frame for any view is always expressed in its parent's coordinate system. Try converting containerView.bounds instead. Or ask gridView to make the conversion instead.