@SanMao
2015-10-12T16:05:03.000000Z
字数 2412
阅读 1414
知识补充
+(void)load
{
}
-(void)loadView
{
}
- (void)viewDidLoad;
// Called after the view has been loaded. For view controllers created in code, this is after -loadView. For view controllers unarchived from a nib, this is after the view is set.
- (void)viewWillAppear:(BOOL)animated;
// Called when the view is about to made visible. Default does nothing
- (void)viewDidAppear:(BOOL)animated;
// Called when the view has been fully transitioned onto the screen. Default does nothing
- (void)viewWillDisappear:(BOOL)animated;
// Called when the view is dismissed, covered or otherwise hidden. Default does nothing
- (void)viewDidDisappear:(BOOL)animated;
// Called after the view was dismissed, covered or otherwise hidden. Default does nothing
+ (void)initialize
{
}
- 自动调用drawRect方法来实现view的绘制,方便绘图
drawRect方法的调用情况
:
如果在UIView初始化时没有设置rect大小,将直接导致drawRect不被自动调用。drawRect调用是在Controller->loadView, Controller->viewDidLoad 两方法之后掉用的.所以不用担心在控制器中,这些View的drawRect就开始画了.这样可以在控制器中设置一些值给View(如果这些View draw的时候需要用到某些变量值).
该方法在调用sizeToFit后被调用,所以可以先调用sizeToFit计算出size。然后系统自动调用drawRect:方法。
drawRect方法使用注意点
:
- 默认调用layoutSubviews来实现view中subView的重新布局,方便出来数据
layoutSubviews方法的调用情况
: - 异步调用layoutIfNeeded刷新布局,不是立即刷新只是做一个刷新布局的标记,内部调用layoutSubviews