iOS的layout机制相关方法

来源:互联网 发布:出境旅游数据 编辑:程序博客网 时间:2024/06/05 11:11
- (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
原创粉丝点击