convertRect, convertPoint
2018-11-21 10:09 法子 阅读(436) 评论(0) 编辑 收藏 举报参考文章:http://www.cnblogs.com/chenyg32/p/4800420.html
想获取在其他控件里的button相对与整个self.view的frame
CGRect rect = [self.view convertRect:_button.frame fromView:_button.superview];
CGRect rect = [_button.superview convertRect:_button.frame toView:self.view];
let rect = self.view.convert(button.frame, from: button.superview)
let rect = button.superview?.convert(button.frame, to: self.view)
想获取(相对于屏幕的坐标的)触摸点相对于某个tableView的坐标
//view参数为nil则表示整个屏幕 CGPoint tablePT = [_tableView convertPoint:screenPoint fromView:nil]; CGPoint tablePT = [[UIApplication sharedApplication].delegate.window convertPoint:screenPoint toView:_tableView];
let point = tableView.convert(screenPoint, from: nil) let point = UIApplication.shared.delegate?.window?.convert(screenPoint, to: tableView)