ios UIView layoutSubviews调用时机
2015-11-09 13:50
459 查看
iOS 官方文章中对UIView的layoutSubviews 介绍如下:
The default implementation of this method does nothing on iOS 5.1 and earlier. Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subviews.
Subclasses can override this method as needed to perform more precise layout of their subviews. You should override this method only if the autoresizing and constraint-based behaviors of the subviews do not offer the behavior you want. You
can use your implementation to set the frame rectangles of your subviews directly.
You should not call this method directly. If you want to force a layout update, call the setNeedsLayout method instead to do so prior to the next drawing update. If you want to update the layout
of your views immediately, call the layoutIfNeeded method.
大致意思是 iOS5.1之前这个方法没有任何作用。这个方法默认功能是控制一个子view的大小和位置
凡事继承UIView的子类都都可以实现这个方法,来控制子视图。实现次方法的前提是你觉得系统布局不能满足你的要求,你可以在这个方法里面做更为精确的设置
这个方法你无需调用。如果你想要更新layout的话 可以调用这个方法:setNeedsLayout 来实现。如果不想立刻刷新layout 你可以调用layoutIfNeeded 方法
下面我们研究下这个方法调用的时机
1.init初始化的时候是不会触发的。但是调用initWiftFrame 并且参数fram不为0的时候会调用.换句话就是大小或者位置更改的时候调用。
2,添加子视图的时候会调用(即调用addsubView方法的时候)
3,修改了frame的时候调用(1,也属于此类情况)
4,UIScrollView滚动的时候会调用此方法
5,屏幕旋转的时候会调用
6,子视图修改的时候会调用父级视图的此方法
The default implementation of this method does nothing on iOS 5.1 and earlier. Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subviews.
Subclasses can override this method as needed to perform more precise layout of their subviews. You should override this method only if the autoresizing and constraint-based behaviors of the subviews do not offer the behavior you want. You
can use your implementation to set the frame rectangles of your subviews directly.
You should not call this method directly. If you want to force a layout update, call the setNeedsLayout method instead to do so prior to the next drawing update. If you want to update the layout
of your views immediately, call the layoutIfNeeded method.
大致意思是 iOS5.1之前这个方法没有任何作用。这个方法默认功能是控制一个子view的大小和位置
凡事继承UIView的子类都都可以实现这个方法,来控制子视图。实现次方法的前提是你觉得系统布局不能满足你的要求,你可以在这个方法里面做更为精确的设置
这个方法你无需调用。如果你想要更新layout的话 可以调用这个方法:setNeedsLayout 来实现。如果不想立刻刷新layout 你可以调用layoutIfNeeded 方法
下面我们研究下这个方法调用的时机
1.init初始化的时候是不会触发的。但是调用initWiftFrame 并且参数fram不为0的时候会调用.换句话就是大小或者位置更改的时候调用。
2,添加子视图的时候会调用(即调用addsubView方法的时候)
3,修改了frame的时候调用(1,也属于此类情况)
4,UIScrollView滚动的时候会调用此方法
5,屏幕旋转的时候会调用
6,子视图修改的时候会调用父级视图的此方法
相关文章推荐
- UINavigationController视图控制器切换(一)
- UINavigationController视图控制器切换(一)
- UIViewController 切换及简单动画
- UIViewController 切换及简单动画
- opencv4android 中 Highgui.imread not found 的问题
- 移动端 UI 适配最佳实践(上)
- UIView使用CALayer添加单独一边
- Handler,Looper,Message,MessageQueue,Thread机制的深入理解(举例说明)
- Deploy .Net project automatically with MsBuild and MsDeploy (1)
- 在request中获取项目路径
- UI界面-绝对布局
- UIView,UIButton,UIImageView等设置圆角,设置阴影,设置边框的方法
- iOS [UIScreen mainScreen].scale
- UIView 属性和方法
- FineUI(开源版)v4.2.2发布(8年125个版本,官网示例突破300个)!
- 设置 UISearchBar 输入字体颜色 和 默认字体颜色
- UIalertController日期控件
- AlertDialog.Builder对话框类的用法
- iOS开发 获取手机信息(UIDevice,NSBundle,NSlocale)
- UI界面-表格布局