iOS的layout机制相关方法

- (CGSize)sizeThatFits:(CGSize)size {
    return CGSizeMake(100, 100);
    //Asks the view to calculate 
    //and return the size that best fits the specified size.
}
//sizeToFit会自动调用sizeThatFits方法;
- (void)sizeToFit {
    //You should not override this method.
    //If you want to change the default sizing information for your view,
    //override the sizeThatFits: instead.   
}

//1.init初始化不会触发layoutSubviews
//2.用initWithFrame 进行初始化时(rect不能为0)或者改变frame会触发
//3.addSubview会触发
//4.滚动ScrollView也会触发
//5.旋转Screen会触发superView上的layoutSubviews事件
//6.改变一个View的大小的时候也会触发superView上的layoutSubviews事件
- (void)layoutSubviews {
//Lays out 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.


}

- (void)layoutIfNeeded {
//Lays out the subviews immediately.
//Use this method to force the layout of subviews before drawing.
}

- (void)setNeedsLayout {

}

- (void)setNeedsDisplay {
//You can use this method or the setNeedsDisplayInRect: 
//to notify the system that your view’s contents need to be redrawn
}

- (void)setNeedsDisplayInRect:(CGRect)rect {
}

- (void)drawRect:(CGRect)rect {
//Only override drawRect:
//if you perform custom drawing.  
}

- (void)viewWillLayoutSubviews {
//Called to notify the view controller that its view is about to layout its subviews.
}

- (void)viewDidLayoutSubviews {
//Your view controller can override this method to make changes 
//after the view lays out its subviews.   
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值