ios setNeedsLayout 和 setNeedsDisplay

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14506968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:59:59  来源:igfitidea点击:

setNeedsLayout and setNeedsDisplay

iosautolayoutsetneedsdisplay

提问by DuckDucking

What is the real difference between UIViewmethods setNeedsLayoutand setNeedsDisplay?

UIView方法setNeedsLayout和之间的真正区别是什么setNeedsDisplay

As usual documentation is foggy about this.

像往常一样,文档对此很模糊。

回答by Joris Kluivers

Actually the documentation is pretty clear about this:

实际上,文档对此非常清楚:

  • setNeedsLayoutwill layout subviews

    Call this method on your application's main thread when you want to adjust the layout of a view's subviews.

  • setNeedsDisplaywill call for a redraw of your view (drawRect:, etc).

    You can use this method or the setNeedsDisplayInRect: to notify the system that your view's contents need to be redrawn.

  • setNeedsLayout将布局子视图

    当您想要调整视图子视图的布局时,请在应用程序的主线程上调用此方法。

  • setNeedsDisplay将要求重绘您的视图(drawRect:等)。

    您可以使用此方法或 setNeedsDisplayInRect: 通知系统您的视图内容需要重绘。