在 macOS 项目中,我试图获取并设置 NSTableView 的滚动光标位置,代码似乎可以正常工作,因为不显示错误但光标不更新。
var clipOrigin = tableView.enclosingScrollView?.contentView.bounds.origin // get the position
clipOrigin = CGPoint (x: 0.0, y: 3.0) // set a new position
tableView.enclosingScrollView?.contentView.scroll(to: clipOrigin!) // set the new position
我是不是忘记了什么?
最佳答案
contentView.bounds.origin
几乎肯定会给您 0,0
点,因为这不是您期望的值。 bounds
告诉您有关显示 Canvas 的 View 位置的信息,而不是滚动文档的内部偏移量。
我猜 -documentRect
或 -documentVisibleRect
属性包含您要查找的正确偏移值。
关于swift - 如何在 Swift 中保存和恢复 NSScrollView 滚动位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43770793/