如果 setHasHorizontalScroller:NO,NSScrollView 可以滚动吗?
是否可以“隐藏” NSScrollView 的滚动条并仍然获得手势滚动行为?
Is it possible to 'hide' the scrollers of an NSScrollView and still get gestural scrolling behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
创建一个 NSScroller 子类并将其设置为 NSScrollView 实例的垂直/水平滚动条。
NSScroller 子类应该重写它(10.7 及更高版本):
Create an NSScroller subclass and set it as the vertical/horizontal scroller for the NSScrollView instance.
The NSScroller subclass should override this (10.7 and above):
这绝对是 AppKit 中的一个错误。我可以使用以下任一解决方案在 10.8.5 上实现此功能:
1) NSScroller 子类(首选方法)
来源:jmk 在 https://stackoverflow.com/a/12960795/ 836263
2) 使用传统风格时,反弹和势头似乎被破坏了。它还部分破坏了 Apple 的滚动同步 代码。如果一个是
NSScrollerStyleOverlay
,另一个是NSScrollerStyleLegacy
,它会导致滚动视图重置滚动位置。如果覆盖式滚动视图被滚动,则传统样式被滚动,它将两个滚动视图重置为顶部 y=0 滚动偏移量。This is definitely a bug in AppKit. I was able to get this working on 10.8.5 using either of the following solutions:
1) Subclass NSScroller (preferred method)
Source: jmk in https://stackoverflow.com/a/12960795/836263
2) Bounce-back and momentum seems broken when using the legacy style. It also partially breaks Apple's scroll synchronization code. It causes the scroll views to reset scroll position if one is
NSScrollerStyleOverlay
and the other isNSScrollerStyleLegacy
. If the overlay-style scroll view is scrolled, then the legacy style is scrolled, it resets both scroll views to the top y=0 scroll offset.导致滚动视图不显示滚动条且不响应手势滚动:
导致显示禁用的滚动条,但它响应手势滚动:
Causes the scrollview to not display a scroller and not respond to gestural scrolling:
Causes a disabled scroller to be displayed, but it responds to gestural scrolling:
是的,这是可能的。初始化滚动视图后立即尝试此操作。
我已经让它工作,无需隐藏
NSScroller
子类,也无需触及setHasVerticalScroller:
。另外,如果self.scrollView
是重写drawRect:
的子类,请尝试将其关闭,以确保您在那里所做的操作不会导致问题。Yes, it is possible. Try this soon after initializing the scrollView.
I've gotten this to work without hiding an
NSScroller
subclass and without touchingsetHasVerticalScroller:
. Also, ifself.scrollView
is a subclass that overridesdrawRect:
, try turning that off to make sure that what you're doing there isn't causing the problem.你为什么不尝试一下呢?
回答这个问题:是的,如果用户拥有带滚轮的鼠标或具有滚动功能的触摸板,尽管滚动条不可见,但仍然可以滚动视图。
Why don't you just try it?
To answer the question: Yes, if the user has mouse with a scroll wheel or a a scrolling-capable touchpad, it is still possible to scroll the view, despite the scrollers being invisible.