有没有办法让自定义 NSView 知道它是否嵌入到 NSScrollView 中?
我正在创建一个自定义 NSView 来显示一些内容。
当我的 View 放置在窗口或另一个 View 中时,其大小是固定的,并且内容会被裁剪为可用大小。
当我的 View 放置在 NSScrollView 中时,必须根据内容调整其大小,以便在必要时可以滚动。
我知道我可以在 View 中添加一个成员,指定托管我的 View 的 NSScrollView 并在代码中手动设置该成员,但我想知道是否还有其他方法?
最佳答案
你没有检查NSView
的方法吗?
@property(只读,强) NSScrollView *enendingScrollView;
或
var enleadingScrollView: NSScrollView? { 获取 }
The nearest ancestor scroll view that contains the current view.
If the current view is not embedded inside a scroll view, the value of this property is nil. This property does not contain the current view if the current view is itself a scroll view. It always contains an ancestor scroll view.
关于cocoa - 嵌入 NSSscrollView 的自定义 NSView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44495260/