iOS 获取控件相对屏幕(父N级)坐标位置

需要获取坐标的对象为label,则该视图相对屏幕的位置,可使用下面方法实现:

    NSInteger index = _index + 100;

    UILabel *label = [[self.view viewWithTag:_selectCellIndex] viewWithTag:index];

    

    UIWindow * window=[[[UIApplication sharedApplication] delegate] window];

    CGRect rect=[label convertRect: label.bounds toView:window];

该方法可以获取任意线性点层级视图绝对坐标,层级不深时非常好用。

posted @ 2017-03-14 21:33  aba-solution  阅读(3560)  评论(0编辑  收藏  举报