如何获取控件相对于屏幕的坐标
2016-03-24 本文已影响1599人
罗小耳
一句核心代码搞定:“控件名称 + convertRect: 控件坐标 + toView: 屏幕”
// 获取相对于self.view的坐标
DistributTimeCell *timeCell = [_flowerCheckTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:3]];
CGRect cellFrame = [timeCell.timerBtn convertRect:timeCell.timerBtn.frame toView:self.view];
// 获取相对于屏幕的坐标
UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
CGRect rect=[bView convertRect: bView.bounds toView:window];