繁体   English   中英

直接从iOS中的Self.view计算UIButton的起源

[英]Calculating The Origin of UIButton Directly from the Self.view in iOS

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

在此输入图像描述

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

任何意见或建议将不胜感激。

先感谢您。

对于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];

你可以试试这个


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


frame包含与self.view相关的原始信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM