Cocoa:在应用程序启动时隐藏文本视图的自定义滚动条
我已经为我的文本视图创建了一个自定义滚动条(在滚动视图的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
奇怪的是,在将自定义滚动器添加到滚动视图之前,我必须使用 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 usesetHasVerticalScroller:NO
in the document's windowControllerDidLoadNib method, using it just after having added the scrollbar in the scrollview'sawakeFromNib
method won't work. Well, at least now it seems to work!我总是使用 IB 来设置滚动条,然后如果我想抑制其中之一,则使用以下行:
尝试在 awakeFromNib 中使用该行,稍后如果用户选择将其设置为 YES,而不是使用“隐藏”属性。
PS 在IB中添加的NSTextView总是嵌入在NSScrollView中,并且它是控制滚动条的滚动视图。因此,如果上述方法不起作用,请尝试在文本视图的超级视图上调用 setHasWhateverScroller :
如果收到“无法识别的选择器”错误,则尝试将超级视图显式转换为 NSScrollView (只有当超级视图确实是NSScrollView):
I've always used IB to set up scrollbars and then used the following line if I want to suppress one of them:
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:
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):