您的位置:首页 > 移动开发 > IOS开发

iOS开发-获取子视图坐标系中Point、Rect在父视图坐标系中的实际值

2015-09-07 17:01 555 查看
iOS提供了方法来完成上述值得转换

convertRect:toView:, convertRect:FromView:

convertPoint:toView: and convertPoint:fromView: methods

这里以convertRect:FromView:为例,文档中对该方法的描述:

Converts a point from the coordinate system of a given view to that of the receiver.

将一个指定view中的Rect转换成方法调用者所处坐标系的Rect

每一个View自身都有一套坐标系,原点在(0,0),宽和高,对应View中的bounds

而View中frame的orgin值,是该视图orgin点在其父视图坐标系的位置

在我们的应用中,最外层视图的orgin(0,0)对应屏幕的左上方的点。

举例:有两个视图A、B,B是A的子视图,并且B被添加在A中的20,30位置。那么B视图坐标系中的0,0对应

A视图坐标系的20,30,这个的转换过程就是上述方法提供的功能。

通过上述这些方法我们可以查看子视图中的点在父视图中的位置,比如检查视图是否在屏幕中

CGPoint originInSuperview = [superview convertPoint:CGPointZero fromView:subview];


  

ref
http://stackoverflow.com/questions/8465659/understand-convertrecttoview-convertrectfromview-convertpointtoview-and
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: