【问题标题】:Calculating The Origin of UIButton Directly from the Self.view in iOSiOS 中直接从 Self.view 计算 UIButton 的原点
【发布时间】:2013-12-24 07:08:28
【问题描述】:

我的对象的层次结构如下,

假设 UIButton 的对象名称是“myButton”。
现在,有没有办法直接从 self.view 计算“myButton”的原点(X 坐标,Y 坐标),而不是使用任何中间对象的框架

任何 cmets 或建议将不胜感激。

提前谢谢你。

【问题讨论】:

    标签: ios iphone objective-c frame subviews


    【解决方案1】:

    对于 UIView

    - (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;
    - (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;
    
    CGPoint pt = [button converPoint:button.bound.origin toView:self.view];
    

    【讨论】:

      【解决方案2】:

      你可以试试这个


       CGRect frame =  [button convertRect:button.bounds toView:self.view];
      


      frame 包含相对于 self.view 的原点信息

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-05-23
        • 1970-01-01
        • 1970-01-01
        • 2011-03-24
        • 1970-01-01
        • 2022-06-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多