本文将简要讨论以下几个问题:
1、UIView的drawRect方法的调用机制及注意点
2、UIView的layoutSubviews、layoutIfNeeded、setNeedsLayout等方法的调用机制
3、如何通过更新view的约束值来实现动画效果
博客配图
重绘机制 - drawRect
方法定义
Drawing and Updating the View
-drawRect:
Draws the receiver’s image within the passed-in rectangle.
-setNeedsDisplay
Marks the receiver’s entire bounds rectangle as needing to be redrawn.
-setNeedsDisplayInRect:
Marks the specified rectangle of the receiver as needing to be redrawn.
- (void)drawRect:(CGRect)rect //重写此方法,执行重绘任务
- (void)setNeedsDisplay //标记为需要重绘,异步调用drawRect
- (void)setNeedsDisplayInRect:(CGRect)rect //标记为需要局部重绘
重绘操作是在drawRect方法中完成,但是苹果不建议直接调用drawRect方法,当然如果你强制直接调用此方法是