objective-c CGAffineTransform 后在父/子 UIView 之间转换坐标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2073427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert coordinates between parent/child UIView after CGAffineTransform
提问by RickiG
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 300x200 and have the same origin. This means that (100, 40) is the same point in both views.
我有一个 UIView,它包含另一个带有地图的 UIView。父 UIView 为地图保存了一些图例。最初我在地图视图中定义了一些坐标。例如 (100, 40),并在父视图中放置一块图形(如谷歌地图中的大头钉等)。父视图和子视图都是 300x200 并且具有相同的原点。这意味着 (100, 40) 在两个视图中都是相同的点。
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.
现在我使用 CGAffineTransform 缩放和移动子 UIView(地图),坐标 (100, 40) 现在位于其他地方。父视图在这里实际上是一个掩码。
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?
我可以使用 CGAffineTransform Matrix 或框架的其他部分来计算并通知父视图在点移动后放置大头钉的位置吗?
i.e. (100, 400) in the child view compared to (100, 40) in the parent view, what does it compare to after the transformation?
即子视图中的 (100, 400) 与父视图中的 (100, 40) 相比,转换后它与什么相比?
Thank you for suggestions or help given.
感谢您提供的建议或帮助。
The animation of the child UIView
子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];
回答by Costique
UIView's -convertPoint:toView:and -convertPoint:fromView:should work for you.
UIView 的-convertPoint:toView:,-convertPoint:fromView:应该为你工作。

