当 TextKit NSTextContainer 大小改变时,我如何接收通知?

How do I receive notifications when TextKit's NSTextContainer's size changes?

我需要知道 TextKitNSTextContainersize 何时更改,以便我可以更新 NSLayoutManager 中的一些缓存。 size 更改时如何接收通知? TextKit 通常(以及 NSTextContainersize 属性 特别地)支持 KVO 吗?我查看了 NSTextContainer.h header 和 NSTextContainer documetation,但无论如何我都找不到任何相关信息。

NSTextContainer 应该在 NSLayoutManager 的大小或形状发生变化时调用 -[NSLayoutManager textContainerChangedGeometry:]

This method is invoked automatically by other components of the text system; you should rarely need to invoke it directly. Subclasses of NSTextContainer, however, must invoke this method any time their size of shape changes (a text container that dynamically adjusts its shape to wrap text around placed graphics, for example, must do so when a graphic is added, moved, or removed).

我还没有对此进行测试以确定是否需要在 NSTextContainer 上设置 heightTracksTextViewwidthTracksTextView;在 NSLayoutManager 上设置 verticallyResizablehorizontallyResizable;或者以编程方式调用 -[NSTextContainer setSize:]-[NSTextContainer setSimpleRectangularTextContainer:] 将自动调用 -[NSLayoutManager textContainerChangedGeometry:] 作为广告。