- (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.
}
iOS的layout機制相關方法
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.