layoutSubview相关

一般来说自定义控件的时候用layoutSubview会比较多,继承自UIControl时重写以下代码

- (void)layoutSubviews
{
    [super layoutSubviews];
    NSLog(@"CustomStepper layoutSubviews");
    // ...stuff...
}

// 初始化自定义的Stepper
- (void)initCustomStepper
{
    CustomStepper *customStepper = [[CustomStepper alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 200.0f, 100.0f)];
    [self.view addSubview:customStepper];
    [customStepper release];
}



1、init初始化不会触发layoutSubviews

2、addSubview会触发layoutSubviews
3、设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化
4、滚动一个UIScrollView会触发layoutSubviews
5、旋转Screen会触发父UIView上的layoutSubviews事件
6、改变一个UIView大小的时候也会触发父UIView上的layoutSubviews事件

你可能感兴趣的:(layoutSubview相关)