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

  • 相关阅读:
    Hadoop
    java获取系统指定时间年月日
    JS获取系统的指定定年月日
    nodetree中 前面复选框禁用插件
    JS生成指定长度的随机数
    Post的请求案例
    Ajax的简单请求案例
    from 表单提交
    Oracle中添加视图
    java double保留小数点的零的问题,java保留小数点问题
  • 原文地址:https://www.cnblogs.com/feiling/p/4789339.html
Copyright © 2011-2022 走看看