I need to draw a line across a custom UIView(i.e. from top-left to bottom-right). However, as far as I know, the coordinate systems are different.
How can I translate between those two coordinate systems?
As long as we are talking about UIView objects that are subview of some other UIView object - the quite normal case - each View is positioned in relation to its next super view. The top left corner of the superview is (0,0).
For most applications that simply works fine. In rather rare cases there may be a need to transform coordinates from one views's sub-view-coordinate-system to that of another view. UIView provides the methods
– convertPoint:toView:
– convertPoint:fromView:
– convertRect:toView:
– convertRect:fromView:
for that usage. They work quite fine. Before you make use of them you should re-think whether that is required and evaluate whether your current view hierarchy could do with a re-desin. :)