基于 NSTableview 视图的滚动性能 [英] NSTableview View Based Scrolling Performance

查看:22
本文介绍了基于 NSTableview 视图的滚动性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 OS X Cocoa 编程还很陌生,但已决定尝试使用新的 Swift 语言.

I am fairly new to OS X Cocoa programming but have decided to give it a go with the new Swift language.

我有一个 NSTableView 有 1500 行(会更多)和 7 列.有一个复选框列,其余是文本字段,一个是日期格式,一个是货币格式.我首先将其设置为基于单元格.滚动非常流畅(我什至做了一个添加 100 万行的测试,仍然很流畅).这是在特立独行的情况下.

I have an NSTableView with 1500 rows (will be more) and 7 columns. There is one checkbox column and the rest are text fields, one with a date formate and one a currency formatter. I first set this up as cell based. Scrolling was buttery smooth (I even did a test adding 1 million rows, still smooth). This was under mavericks.

然后我升级到 Yosemite,滚动性能显着下降.在表格视图上启用核心动画层复选框改善了这一点,但仍然比小牛队差.

I then upgraded to Yosemite, scrolling performance significantly degraded. Enabling Core animation layer checkbox on the table view improved this but was still worse than in mavericks.

在阅读尝试提高优胜美地滚动性能的过程中,我遇到了基于视图的"NSTableView.从文档中可以看出,通常不应使用基于单元格的表格视图,并且仅支持遗留项目.

During my reading trying to improve scroll performance in Yosemite I came across "View-Based" NSTableViews. From the documentation it said cell based table views should generally not be used and are only supported for legacy projects.

因此,我将我的表格转换为基于视图的表格视图.示例简单的概念,没有什么复杂的.滚动性能绝对糟糕.如果你滚动得非常慢,它就足够平滑了,但是一旦你开始更快地滚动,它就像没有足够的缓冲一样,它开始口吃和抽搐.此外,当 NSTableview 被填充时,聚焦和散焦窗口需要一秒钟或更长时间(我再次在小牛队中尝试过,但没有出现,滚动也好一点,但仍然远不及基于单元格).

I therefore converted my table to a View based table view. Sample simple concept, nothing complicated. The scrolling performance is absolutely terrible. If you scroll very slow it is smooth enough but as soon as you start to scroll faster its like it hasn't buffered enough and it starts stuttering and jerking. Also when the NSTableview is populated, focusing and defocusing the window takes a second or more (I tried it in mavericks again and this was not present, scrolling was also a little better, but still nowhere near cell based).

基于视图的 NSTableviews 是否总是不利于滚动性能?如果是这样,为什么苹果建议在基于单元格的 NSTableviews 上使用它们.

Are view based NSTableviews always bad for scrolling performance? If so why do apple recommend using them over cell based NSTableviews.

还有一些应用程序,例如 safari 和 Reeder2,即使在 Yosemite 中也有黄油般的平滑滚动.他们是如何做到这一点的?

Also some applications like safari and Reeder2 have buttery smooth scrolling even in Yosemite. How do they achieve this?

我是否遗漏了某些东西,或者 OS X 的性能是否会因每个新事物而变得糟糕?即

Am I missing something or is the performance of OS X just going to hell with each new thing? I.e

小牛队 > 优胜美地

基于单元格 > 基于视图

Cell-Based > View-Based

旧 > 新

非常感谢任何帮助.谢谢!

Any help is much appreciated. Thanks!

推荐答案

根据 Apple 的说法,OSX 在默认情况下从不启用 QuartzCore(就像 iOS 那样).因此,您需要:

According to Apple, OSX never enable QuartzCore by default (as iOS, instead, do). So, you need to:

  • 在构建设置"窗格下将您的项目链接到 QuartzCore.framework.
  • 为您的主窗口启用 CoreAnimation 层(在 IB 上的 View Effects Inspector 下)(如果可能,请确保在容器视图上启用它,这会给您带来较差的性能).

引用 Apple 文档:

Quoting Apple docs:

在 iOS 应用程序中,始终启用核心动画并且支持每个视图一层.在 OS X 中,应用程序必须明确启用核心动画通过执行以下操作来支持:

In iOS apps, Core Animation is always enabled and every view is backed by a layer. In OS X, apps must explicitly enable Core Animation support by doing the following:

链接到 QuartzCore 框架.(iOS 应用必须链接到仅当它们显式使用 Core Animation 接口时才使用此框架.)通过执行以下操作启用对一个或多个 NSView 对象的层支持以下之一:

Link against the QuartzCore framework. (iOS apps must link against this framework only if they use Core Animation interfaces explicitly.) Enable layer support for one or more of your NSView objects by doing one of the following:

在您的 nib 文件中,使用视图效果检查器启用图层支持你的观点.检查器显示复选框选定的视图及其子视图.建议您启用尽可能在窗口的内容视图中提供图层支持.对于以编程方式创建的视图,调用视图的 setWantsLayer:方法并传递一个 YES 值来指示视图应该使用层.以上述方式之一启用层支持会创建一个层支持的视图.使用层支持的视图,系统需要负责创建底层对象和保持该层更新.在 OS X 中,也可以创建一个层托管视图,您的应用程序由此实际创建和管理底层对象.(您不能在iOS.)有关如何创建层托管视图的更多信息,请参见层托管让你在 OS X 中更改层对象."

In your nib files, use the View Effects inspector to enable layer support for your views. The inspector displays checkboxes for the selected view and its subviews. It is recommended that you enable layer support in the content view of your window whenever possible. For views you create programmatically, call the view’s setWantsLayer: method and pass a value of YES to indicate that the view should use layers. Enabling layer support in one of the preceding ways creates a layer-backed view. With a layer-backed view, the system takes responsibility for creating the underlying layer object and for keeping that layer updated. In OS X, it is also possible to create a layer-hosting view, whereby your app actually creates and manages the underlying layer object. (You cannot create layer-hosting views in iOS.) For more information on how to create a layer-hosting view, see "Layer Hosting Lets You Change the Layer Object in OS X."

更多信息:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/SettingUpLayerObjects/SettingUpLayerObjects.html

这篇关于基于 NSTableview 视图的滚动性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆