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,这个的转换过程就是上述方法提供的功能。
通过上述这些方法我们可以查看子视图中的点在父视图中的位置,比如检查视图是否在屏幕中
ref
http://stackoverflow.com/questions/8465659/understand-convertrecttoview-convertrectfromview-convertpointtoview-and
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
相关文章推荐
- 《IOS_OC》继承、多态、初始化方法、便利构造器
- iOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet
- iOS开发利器-CocoaPods安装和使用教程
- iOS项目部分-控件-TextField常用方法
- iOS远程推送
- iOS Auto Layout文章总结
- iOS多线程学习之NSOperation(二)
- iOS开发最佳实践总结
- iOS中定时器NSTimer使用
- IOS彩票第二天设置界面(2)
- iOS开发 - 证书失效
- IOS CoreText --- 图文混排
- iOS运行时应用场合二 获取对象属性
- iOS应用崩溃日志分析
- IOS CoreText -- 基本用法
- iOS路径获取
- iOS运行时场合一 category中添加(连接)对象(fake机制)
- iOS项目部分-01(注册)-使用正则表达式判断用户输入的是不是手机号码
- BIOS的基本概念和理解
- IOS开发指南学习——视图与控件