zoukankan      html  css  js  c++  java
  • iOS开发-获取子视图坐标系中Point、Rect在父视图坐标系中的实际值

    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

  • 相关阅读:
    ThinkPHP框架返回插入记录的id号
    TP框架中关于if、else 分支结构逻辑错误
    SVN 快速入门!
    TP框架中如何使用SESSION限制登录?
    TP框架M方法 create方法丢失字段问题
    .NET Framework 工具
    X86-64寄存器和栈帧
    微软开源资源 NET Foundation Projects
    Import 元素 (MSBuild)
    C#开源资源项目
  • 原文地址:https://www.cnblogs.com/feiling/p/4789339.html
Copyright © 2011-2022 走看看