我们在转换一个点在两个不同的视图中的坐标时经常用到
UIView的方法
convertPoint:toView:
或者是
convertPoint:fromView:
[aView convertPoint:p toView:anotherView]是指将p相对aView的坐标转换为相对anotherView的坐标
比如说aView是原点(0,0), 宽高(1024, 768)的视图
anotherView是aView的子视图,原点是(100, 0),宽高(200, 200)
那么一个在anotherView中坐标是(0, 0)的点经过转换后在aView的坐标是(100, 0)
convertPoint:fromView:跟上面的方法是一个意思,只是转换的方向不一样而已
我这里把官方文档贴出来更直接点吧
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view
Converts a point from the receiver’s coordinate system to that of the specified view.
Converts a rectangle from the coordinate system of another view to that of the receiver.
本文档详细介绍了如何使用UIView的convertPoint:toView:和convertPoint:fromView:方法进行坐标转换。通过实例展示了如何在不同视图间转换点的坐标,帮助理解这些方法在视图坐标系统中的应用。
989

被折叠的 条评论
为什么被折叠?



