尽管
NSScrollView
是 autohidesScrollers
,但 true
的滚动条在 macOS Sequoia 上仍然可见。在 macOS Sonoma 及更低版本上,滚动条显示为 NSScrollView
的子视图,并在一段时间后正确自动隐藏。它显示在内容上方。在 macOS Sequoia 上,情况发生了变化,滚动条正在占用显示内容的空间。当我使用 NSStackView
时可以看到这一点(当滚动条隐藏/可见时,它将调整内容大小)。仅当我调整窗口/滚动视图的大小时,滚动条才会隐藏。
如何在 macOS Sequoia 上自动隐藏滚动条?或者有什么解决方法可以强制隐藏它吗?
演示问题的简单代码:
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let scrollView = NSScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
scrollView.borderType = .bezelBorder
scrollView.hasVerticalScroller = true
scrollView.hasHorizontalScroller = true
scrollView.autohidesScrollers = true
scrollView.drawsBackground = false
// Create the content view
let contentView = NSView(frame: NSRect(x: 0, y: 0, width: 400, height: 400))
contentView.wantsLayer = true
contentView.layer?.backgroundColor = NSColor.blue.cgColor
// Set the content view to the scroll view
scrollView.documentView = contentView
// Add the scroll view to the main view
self.view.addSubview(scrollView)
// Set Auto Layout constraints
NSLayoutConstraint.activate([
scrollView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 20),
scrollView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: -20),
scrollView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 20),
scrollView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: -20)
])
}
}