UIView中的坐标转换convertPoint:convertRect:
发布日期:2021-11-22 04:28:58 浏览次数:2 分类:技术文章

本文共 810 字,大约阅读时间需要 2 分钟。

使用convertPoint或者convertRect进行坐标转换时,比较重要的是使用convertRect:toView:时,主语一定是view.superView,也就是一个子view的父视图,(反过来convertRect:fromView:也一样)如果直接用子view做主语,在使用转换后的frame做绘制时,会报错,如果引用转换后的frame时,位置是不准的,切记!

UITableViewCell中的subview(btn)frame转换 controllerA

[objc] 
 
 
  1. // controllerA 中有一个UITableView, UITableView里有多行UITableVieCell,cell上放有一个button  
  2. // 在controllerA中实现:  
  3. CGRect rc = [cell convertRect:cell.btn.frame toView:self.view];  
  4. 或  
  5. CGRect rc = [self.view convertRect:cell.btn.frame fromView:cell];  
  6. // 此rc为btn在controllerA中的rect  
  7.   
  8. 或当已知btn时:  
  9. CGRect rc = [btn.superview convertRect:btn.frame toView:self.view];  
  10. 或  
  11. CGRect rc = [self.view convertRect:btn.frame fromView:btn.superview]; 
  12. //如果以上方法写成
  13. CGRect rc = [btn convertRect:btn.frame toView:self.view];
  14. CGRect rc = [self.view convertRect:btn.frame fromView:btn];
  15. //就会报错,或者得到的新frame是错误的

转载地址:https://blog.csdn.net/zxwcool123/article/details/50767983 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:ASIHTTPRequest实现https双向认证请求
下一篇:iOS中 扫描二维码/生成二维码详解

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月10日 13时36分27秒