简体   繁体   中英

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. eg (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 300x200 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?

ie (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的-convertPoint:toView:-convertPoint:fromView:应该适合你。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM