public func layoutSubviews()
public func layoutIfNeeded()
public func setNeedsDisplay()
public func setNeedsDisplayInRect 调用 setNeedsLayout 方法以标记该视图(或者它的子视图)为需要进行布局更新
-调用 setNeedsDisplay 或者 setNeedsDisplayInRect ,而应该在你认为系统默认的布局和重绘不能带给你想要的效果时,在子类中重写这些方法,然后分别通过 setNeedsDisplayInRect: 会给当前 UIView 立一个 flag,以表示后续应该调用 drawRect: 方法,以进行视图重绘 drawRect:setNeedsLayout 和 setNeedsDisplayInRect ----
setNeedsDisplay 补充
setNeedsLayout 的使用场景之前已经提过了(iPad App),下面举个栗子说一下 setNeedsDisplayInRect
通过设置contentMode属性值为UIViewContentModeRedraw,那么将在每次设置或更改frame的时候自动调用drawRect:; 直接调用setNeedsDisplay,或者setNeedsDisplayInRect 执行重绘任务; - (void)setNeedsDisplay;:标记为需要重绘,异步调用drawRect,但是绘制视图的动作需要等到下一个绘制周期执行,并非调用该方法立即执行; - (void)setNeedsDisplayInRect 在其他方法中获取的contextRef都是不生效的; drawRect:方法不能手动调用,需要调用实例方法setNeedsDisplay或者setNeedsDisplayInRect,让系统自动调用该方法
绘图过程中除了使用了drawRect:方法,还有setNeedsDisplay和setNeedsDisplayInRect:。 setNeedsDisplay和setNeedsDisplayInRect:方法是设置视图或者视图部分区域是否需要重新绘制,setNeedsDisplay是重新绘制整个视图,setNeedsDisplayInRect 当遮挡你的视图的其他视图被移动或删除操作的时候; 将视图的hidden属性声明设置为NO,使其从隐藏状态变为可见; 将视图滚出屏幕,然后再重新回到屏幕上; 显式调用视图的setNeedsDisplay或者setNeedsDisplayInRect
4、直接调用setNeedsDisplay,或者setNeedsDisplayInRect:触发drawRect:,但是有个前提条件是rect不能为0。 drawRect:方法不能手动显示调用,必须通过调用setNeedsDisplay 或者 setNeedsDisplayInRect,让系统自动调该方法。
4.直接调用setNeedsDisplay,或者setNeedsDisplayInRect:触发drawRect:,但是有个前提条件是rect不能为0. drawRect:方法不能手动显示调用,必须通过调用setNeedsDisplay或者setNeedsDisplayInRect,让系统自动调该方法。
4、直接调用setNeedsDisplay,或者setNeedsDisplayInRect PS: 重绘操作在drawRect方法中完成,不建议直接调用drawRect方法,当然调用此方法,结果没有任何效果的
4、直接调用setNeedsDisplay,或者setNeedsDisplayInRect:触发drawRect:,但是有个前提条件是rect不能为0。 **drawRect:方法不能手动显示调用,必须通过调用setNeedsDisplay 或 者 setNeedsDisplayInRect,让系统自动调该方法。强行调用也不会起作用的。
相反,应当通过setNeedsDisplay或者setNeedsDisplayInRect:method方法来使这些view失效。这些方法告诉系统view有变化并且需要在下一个节点上来重绘。 不论哪一种content mode生效,你都可以强制使用setNeedsDisplay或者setNeedsDisplayInRect来重绘内容。
layoutIfNeeded] 重绘 -drawRect:(CGRect)rect方法:重写此方法,运行重绘任务 -setNeedsDisplay方法:标记为须要重绘,异步调用drawRect -setNeedsDisplayInRect
layoutIfNeeded] 重绘 -drawRect:(CGRect)rect方法:重写此方法,执行重绘任务 -setNeedsDisplay方法:标记为需要重绘,异步调用drawRect -setNeedsDisplayInRect
let path = UIBezierPath(ovalIn: rect) color.setFill() path.fill() } } 注意: setNeedsDisplayInRect
用 setNeedsDisplayInRect 方法,可以只重画需要更新的部分屏幕,这个方法需要一个表示更新区域的CGRect 结构体作为参数: CGRect mapViewFrame =CGRectMake (150.0,150,75.0,75.0); [ gameLayer setNeedsDisplayInRect:mapViewFrame ]; 如果你在使用 Core Graphics 框架进行绘制
- setNeedsDisplayInRect: Marks the region within the specified rectangle as needing to be updated
当view第一次显示到屏幕上时(加到UIWindow上显示出来) 重绘的时候:调用view的setNeedsDisplay或者setNeedsDisplayInRect:时 1.3 Graphics
才会展示出来 - (void)drawRect:(CGRect)rect的调用时机: 当view第一次显示到屏幕上时(被加到UIWindow上显示出来) 调用view的setNeedsDisplay或者setNeedsDisplayInRect
当view第一次显示到屏幕上时(被加到UIWindow上显示出来) 调用view的setNeedsDisplay或者setNeedsDisplayInRect:时 Quartz2D须知 Quartz2D
而是使用setNeedsDisplay或setNeedsDisplayInRect:方法使view无效。这些方法告诉系统,view的内容改变了,需要在下一个机会重新绘制。 调用setNeedsDisplay或setNeedsDisplayInRect:方法将view(或其subviews)标记为需要重绘。 通知controllers有关对某些数据的更改。 无论哪种内容模式生效,都可以通过调用setNeedsDisplay或setNeedsDisplayInRect:来强制view重绘其内容。
reuseIdentifier: CellIdentifier] autorelease]; } 值得一提的是,cell被重用时,它内部绘制的内容并不会被自动清除,因此你可能需要调用setNeedsDisplayInRect MyTableViewCell *)[self.tableView cellForRowAtIndexPath: indexPath]; cell.image = image; [cell setNeedsDisplayInRect
相反,你可以使用setNeedsDisplay或者setNeedsDisplayInRect:方法使你的视图失效。这些方法会告诉系统这些已改变内容的视图需要在下次机会重新绘制。
opaque; //重新加载绘制内容 - (void)display; //设置内容为需要重新绘制 - (void)setNeedsDisplay; //设置某一区域内容需要重新绘制 - (void)setNeedsDisplayInRect