博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
setNeedsLayout 与 setNeedsDisplay
阅读量:7105 次
发布时间:2019-06-28

本文共 1974 字,大约阅读时间需要 6 分钟。

hot3.png

setNeedsLayout 调用时会调用 - (void)layoutSubviews

setNeedsLayout 在Doc中的定义为:

Call this method on your application’s main thread when you want to adjust the layout of a view’s subviews. This method makes a note of the request and returns immediately. Because this method does not force an immediate update, but instead waits for the next update cycle, you can use it to invalidate the layout of multiple views before any of those views are updated. This behavior allows you to consolidate all of your layout updates to one update cycle, which is usually better for performance.

- (void)layoutSubviews方法在doc中的定义为:

The default implementation of this method does nothing on iOS 5.1 and earlier. Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subviews.

Subclasses can override this method as needed to perform more precise layout of their 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  method instead to do so prior to the next drawing update. If you want to update the layout of your views immediately, call the  method.

由上可见,layoutSubviews 方法是用来设定subview的位置的方法, 是不能手动调用的。只能通过调用setNeedsLayout 方法,来让系统自动调用layoutSubviews方法。

setNeedsDisplay 调用时, 系统会自动调用 drawRect 方法。

setNeedsDisplay 在Doc中的定义如下:

You should use this method to request that a view be redrawn only when the content or appearance of the view change. If you simply change the geometry of the view, the view is typically not redrawn. Instead, its existing content is adjusted based on the value in the view’s  property. Redisplaying the existing content improves performance by avoiding the need to redraw content that has not changed.

转载于:https://my.oschina.net/u/566401/blog/138756

你可能感兴趣的文章
让人沉思的五个问题。
查看>>
web 项目手机页面不允许缩放
查看>>
Atcoder 1973:こだわり者いろはちゃん / Iroha's Obsession
查看>>
访问修饰符protected
查看>>
WPA2-PSK无线密码破解
查看>>
模块的封装之无伤大雅的形式主义
查看>>
dubbo学习(zz)
查看>>
Mybatis(一)
查看>>
react中prop-types的使用
查看>>
C# HttpDirect
查看>>
神奇的勺子
查看>>
QT程序打包发布
查看>>
迭代平方根
查看>>
第六次作业—— Web功能测试(含Selenium IDE实验)
查看>>
mysql字符串的常用函数(截取和拼接)
查看>>
Flex布局教程
查看>>
MongoDB索引的种类与使用
查看>>
CSS基础
查看>>
4-27 参数原来还有很多没有理解 比较详细的解释
查看>>
并发编程的三大注意事项是什么?
查看>>