Cocoa:在应用程序启动时隐藏文本视图的自定义滚动条

发布于 2024-11-07 10:18:07 字数 190 浏览 6 评论 0原文

我已经为我的文本视图创建了一个自定义滚动条(在滚动视图的 awakeFromNib 方法中启动它),现在我想让用户选择是否要在应用程序启动时显示滚动条。问题是,即使我在创建滚动条并将其设置为滚动视图的滚动条后立即将其隐藏,滚动条始终会出现。奇怪的是,在触发事件后尝试隐藏滚动条(例如通过单击首选项中的复选框),滚动条会正确隐藏和显示。我做错了什么?任何帮助表示赞赏!

I've created a custom scroller for my textview (initiating it in the awakeFromNib method of the scrollview) and now I want to let the user chose if he wants to show the scrollbar on application startup. The problem is that the scroller always appears even if I hide it immediately after I created it and set it to be the scroller of the scrollview. The weird thing is that trying to hide the scroller after an event has been triggered (for example by clicking on a checkbox in the preferences) the scroller properly hides and shows. What I'm I doing wrong? Any help is appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生生漫 2024-11-14 10:18:07

奇怪的是,在将自定义滚动器添加到滚动视图之前,我必须使用 setHasVerticalScroller:YES ,否则我无法使用两指滚动手势进行滚动。然后,如果用户不想显示滚动条,我必须在文档的 windowControllerDidLoadNib 方法中使用 setHasVerticalScroller:NO ,在滚动视图的 awakeFromNib< 中添加滚动条后立即使用它/code> 方法不起作用。好吧,至少现在看来是有效的!

The weird thing is that before adding the custom scroller to the scrollview I have to use setHasVerticalScroller:YES, otherwise I can't scroll using the two-fingers scroll gesture. Then, if the user doesn't want the scrollbar to be shown I have to use setHasVerticalScroller:NO in the document's windowControllerDidLoadNib method, using it just after having added the scrollbar in the scrollview's awakeFromNib method won't work. Well, at least now it seems to work!

赠佳期 2024-11-14 10:18:07

我总是使用 IB 来设置滚动条,然后如果我想抑制其中之一,则使用以下行:

[self.aScrollView setHasHorizontalScroller:NO]; // so only the vertical scrollbar is active

尝试在 awakeFromNib 中使用该行,稍后如果用户选择将其设置为 YES,而不是使用“隐藏”属性。

PS 在IB中添加的NSTextView总是嵌入在NSScrollView中,并且它是控制滚动条的滚动视图。因此,如果上述方法不起作用,请尝试在文本视图的超级视图上调用 setHasWhateverScroller :

[[[aTextView superview] superview] setHasHorizontalScroller:NO];

如果收到“无法识别的选择器”错误,则尝试将超级视图显式转换为 NSScrollView (只有当超级视图确实是NSScrollView):

[(NSScrollView *)[[aTextView superview] superview] setHasHorizontalScroller:NO];

I've always used IB to set up scrollbars and then used the following line if I want to suppress one of them:

[self.aScrollView setHasHorizontalScroller:NO]; // so only the vertical scrollbar is active

Try using that line in awakeFromNib, later setting it to YES if user chooses, rather than using the "hidden" property.

P.S. An NSTextView added in IB is always embedded in an NSScrollView, and it's the scrollview that governs the scrollbars. So if the above doesn't work, try calling setHasWhateverScroller on the superview of your textview:

[[[aTextView superview] superview] setHasHorizontalScroller:NO];

If you get an "unrecognized selector" error, then try explicitly casting the superview to NSScrollView (which will work only if the superview really is an instance of NSScrollView):

[(NSScrollView *)[[aTextView superview] superview] setHasHorizontalScroller:NO];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文