如何在Swift中保存和还原NSScrollview滚动位置



在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告诉您有关显示画布的视图位置的信息,而不是滚动文档的内部偏移。

我猜一个-documentRect-documentVisibleRect属性包含您要寻找的正确偏移值。

最新更新