博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS 怎么获取view在父类中的frame, 或子控件位置转换成父控件位置
阅读量:7037 次
发布时间:2019-06-28

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

#怎么获取view在父类中的frame, 或者说 父类UIView中SubView的坐标怎么转换成在父类UIView中的坐标

// 将像素point由point所在视图转换到目标视图view中,返回在目标视图view中的像素值- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;// 将像素point从view中转换到当前视图中,返回在当前视图中的像素值- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;// 将rect由rect所在视图转换到目标视图view中,返回在目标视图view中的rect- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;// 将rect从view中转换到当前视图中,返回在当前视图中的rect- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;例把UITableViewCell中的subview(btn)的frame转换到 controllerA中// controllerA 中有一个UITableView, UITableView里有多行UITableVieCell,cell上放有一个button// 在controllerA中实现:CGRect rc = [cell convertRect:cell.btn.frame toView:self.view];或CGRect rc = [self.view convertRect:cell.btn.frame fromView:cell];// 此rc为btn在controllerA中的rect或当已知btn时:CGRect rc = [btn.superview convertRect:btn.frame toView:self.view];或CGRect rc = [self.view convertRect:btn.frame fromView:btn.superview];复制代码

子控件位置转换成父控件的位置

CGRect focusFrame = [_scrollView convertRect:_joinView.frametoView:self.view];这里_scrollView是self.view的子控件_joinView是_scrollView的子控件,这里是计算出_joinView在self.view的位置,当然还有其他类似的方法[view convertPoint:<#(CGPoint)#> fromView:<#(UIView *)#>][view convertPoint:<#(CGPoint)#> toView:<#(UIView *)#>][self.view convertRect:<#(CGRect)#> fromView:<#(UIView *)#>][self.view convertRect:<#(CGRect)#> toView:<#(UIView *)#>]复制代码

转载于:https://juejin.im/post/5a3238926fb9a044fd11c98b

你可能感兴趣的文章
让人恼火的经历——手机H5网页被注入广告
查看>>
LInq之Take Skip TakeWhile SkipWhile Reverse Union Concat 用法
查看>>
spring装配集合
查看>>
mysql高可用架构方案之中的一个(keepalived+主主双活)
查看>>
SpringMVC案例2----基于spring2.5的注解实现
查看>>
SpringBoot编写自定义的starter 专题
查看>>
北京服务业占GDP比重达81.7%
查看>>
2016年深圳市服务业占GDP比重首次突破六成
查看>>
Oracle基础(四)pl/sql
查看>>
Woody的Python学习笔记2
查看>>
虚函数相关问题分析
查看>>
js代码从页面移植到文件里失效或js代码改动后不起作用的解决的方法
查看>>
java点滴之volatilekeyword特性
查看>>
python 回溯法 子集树模板 系列 —— 13、最佳作业调度问题
查看>>
java位运算应用
查看>>
Gulp自动化构建工具的简单使用
查看>>
[Java开发之路](6)File类的使用
查看>>
less01
查看>>
P3373 【模板】线段树 2 区间求和 区间乘 区间加
查看>>
不用asp.net MVC,用WebForm照样能够实现MVC
查看>>