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

  • 相关阅读:
    triangle
    Synchronizing timer
    jenkins 安装网址
    Java I/O编程思路
    SpEL快速入门
    Spring ApplicationContext的事件机制
    畅谈Spring设计哲学
    Spring ApplicationContext的国际化支持
    SQL中 WHERE与HAVING的区别
    Hibernate的查询语言之HQL(二)——Hibernate查询的from字句
  • 原文地址:https://www.cnblogs.com/feiling/p/4789339.html
Copyright © 2011-2022 走看看