Custom NSView embedded in NSSscrollView

不问归期 提交于 2020-01-05 09:11:43

问题


Is there a way for a custom NSView to know whether it is embedded in a NSScrollView or not?

I am creating a custom NSView for displaying some content.
When my view is placed in a window or another view, its size is fixed and the content is clipped to available size.
When my view is placed in a NSScrollView its size must be adjusted according to content so it can be scrolled if necessary.
I know I can add a member in my view that specifies the NSScrollView that hosts my view and set this member manually in code, but I was wondering if there is another way?


回答1:


You didn't check the methods of NSView?

@property(readonly, strong) NSScrollView *enclosingScrollView;

or

var enclosingScrollView: NSScrollView? { get }

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.



来源:https://stackoverflow.com/questions/44495260/custom-nsview-embedded-in-nssscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!