iOS UIView layoutSubviews调用时机
2015-09-18 10:47
441 查看
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,子视图修改的时候会调用父级视图的此方法
基本归纳了这么多,大家可以继续研究分享
苹果开发群 :414319235 欢迎加入 欢迎讨论问题
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,子视图修改的时候会调用父级视图的此方法
基本归纳了这么多,大家可以继续研究分享
苹果开发群 :414319235 欢迎加入 欢迎讨论问题
相关文章推荐
- 关于UIStoreBoard的Top space to:Top Layout Guide
- UILabel自动换行
- vickate _触摸事件处理 实现UIView替代UIButton
- DedeCMS Error: (PHP 5.3 and above) Please set request_order
- POJ 1947 Rebuilding Roads (树形DP)
- Xcode7 *** does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE)
- MessageQueue.IdleHandler接口使用方法以及原理分析
- 非静态的字段、方法或属性“System.Web.UI.Page.ClientScript...”要求对象引用 (封装注册脚本)
- easyUi datagrid实时刷新的闪屏问题
- 我收集了多个android界面UI效果,深感大哥们的分享啊
- 点击页面,UINavigationController导航栏的隐藏和显示
- Android进阶之动态加载图片(runOnUiThread/handler)
- 【设计模式】-建造者模式-Builder
- Android异步更新UI的方式之使用Handler的post(Runnabel r)方法
- AndroidRuntimeException: requestFeature() must be called before adding content
- php随笔-正则匹配&php浅复制&require跟include
- UI初级连载十一-------触摸与手势
- iOS项目开发实战——使用UICollectionView实现瀑布流
- 命令行和界面程序同时使用
- Android酷炫实用的开源框架(UI框架)