【发布时间】:2013-12-24 07:08:28
【问题描述】:
我的对象的层次结构如下,
假设 UIButton 的对象名称是“myButton”。
现在,有没有办法直接从 self.view 计算“myButton”的原点(X 坐标,Y 坐标),而不是使用任何中间对象的框架?
任何 cmets 或建议将不胜感激。
提前谢谢你。
【问题讨论】:
标签: ios iphone objective-c frame subviews
我的对象的层次结构如下,
假设 UIButton 的对象名称是“myButton”。
现在,有没有办法直接从 self.view 计算“myButton”的原点(X 坐标,Y 坐标),而不是使用任何中间对象的框架?
任何 cmets 或建议将不胜感激。
提前谢谢你。
【问题讨论】:
标签: ios iphone objective-c frame subviews
对于 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 的原点信息
【讨论】: