how Convert coordinates between parent/child UIView after CGAffineTransform



Before I go into doing everything by hand I would like to ask if there is some help to get from the framework.

I have a UIView that holds another UIView with a map. The parent UIView holds some legends for the map. Initially I define some coordinates in the map view. e.g. (100, 40), and place a piece of graphics there in the parent view (like a tack in google maps etc.). The parent view and the child view are both 300×200 and have the same origin. This means that (100, 40) is the same point in both views.

Now I zoom and move the child UIView(the map) using CGAffineTransform and the coordinate (100, 40) is now situated somewhere else. The parent view is effectively a mask here.

Can I use the CGAffineTransform Matrix or another part of the framework to calculate and inform the parent view where to place the tack now that the point has moved?

i.e. (100, 400) in the child view compared to (100, 40) in the parent view, what does it compare to after the transformation?

Thank you for suggestions or help given.

The animation of the child UIView

    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:1.0]; 
    CGAffineTransform transform = CGAffineTransformMakeScale(1.8f, 1.8f);
    worldMap.transform = transform;
    worldMap.bounds.origin = newPos;
    [UIView commitAnimations];





UIView’s -convertPoint:toView: and -convertPoint:fromView: should work for you.


Facebook Comments

Post a comment