嵌入在NSSscrollView中的自定义NSView [英] Custom NSView embedded in NSSscrollView

查看:122
本文介绍了嵌入在NSSscrollView中的自定义NSView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自定义NSView是否有办法知道它是否嵌入在NSScrollView中?

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

我正在创建一个自定义NSView来显示一些内容。 br />
当我的视图放置在窗口或其他视图中时,它的大小是固定的,内容被裁剪为可用的大小。

将视图放置在NSScrollView中时,必须根据内容调整其大小,以便可以在必要时进行滚动。

我知道我可以在视图中添加成员它指定了承载我的视图的NSScrollView并在代码中手动设置了该成员,但我想知道是否还有其他方法?

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?

推荐答案

您没有检查 NSView 的方法吗?

@property(只读,强)NSScrollView * enclosingScrollView;

var enclosingScrollView:NSScrollView? {get}


包含当前视图的最接近的祖先滚动视图。

The nearest ancestor scroll view that contains the current view.

如果当前视图未嵌入在滚动视图内,则此属性的值为nil。如果当前视图本身是滚动视图,则此属性不包含当前视图。它始终包含一个祖先滚动视图。

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.

这篇关于嵌入在NSSscrollView中的自定义NSView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆