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

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

问题描述

我是 OS X Cocoa 编程的新手,但决定使用新的Swift语言。



具有1500行(将是更多)和7列的 NSTableView 。有一个复选框列,其余的是文本字段,一个带有日期格式,一个是货币格式化。我首先设置为基于单元格。滚动是平滑的(我甚至做了一个测试增加100万行,仍然平滑)。



我随后升级到 Yosemite ,滚动性能大大降低。



在阅读过程中,我尝试改善Yosemite的滚动效果,我遇到了View-基于NSTableViews。从文档中,它说基于单元格的表视图通常不应该使用,只支持旧的项目。



因此,我将表转换为基于视图的表视图。样品简单的概念,没有什么复杂。滚动性能是绝对可怕的。如果你滚动非常慢,它是足够平滑,但只要你开始滚动更快,因为它没有缓冲足够,它开始口吃和狂飙。此外,当 NSTableview 被填充,聚焦和散焦窗口需要一秒或更多(我试过它在特立独行者再次,这不存在,滚动也有一点更好,



是否基于视图 NSTableviews 总是不利于滚动性能?如果是这样,为什么苹果建议使用它们基于细胞的 NSTableviews



还有一些应用程序,如safari和Reeder2,甚至在优胜美地也有平滑的滚动。他们如何实现这一点?



我缺少一些东西,或者是OS X的性能只是到每一个新东西的地狱? Ie


Mavericks> Yosemite



基于细胞的> p>

旧>新


任何帮助都非常感谢。谢谢!

解决方案

根据苹果,OSX从来没有启用QuartzCore默认情况下因此,您需要:




  • 在Build Settings窗格下链接QuartzCore.framework您的项目。

  • 为您的主窗口启用CoreAnimation Layer(在IB的视图效果检查器下)(如果可能,否则请确保在容器视图上启用它,导致性能较差)。



引用Apple文档:


在iOS应用程序中,Core Animation始终处于启用状态,
由一层。在OS X中,应用程序必须通过执行以下操作来显式启用Core Animation
支持:



链接到QuartzCore框架。 (iOS应用程序必须链接到
这个框架,只有当他们使用Core Animation接口显式。)
通过执行
启用对一个或多个NSView对象的图层支持:



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


详情: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/SettingUpLayerObjects/SettingUpLayerObjects.html


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

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.

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.

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.

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).

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

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

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

Mavericks > Yosemite

Cell-Based > View-Based

Old > New

Any help is much appreciated. Thanks!

解决方案

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

  • link against QuartzCore.framework your project under Build Settings pane.
  • enable CoreAnimation Layer (under View Effects Inspector on IB) for your main window (if possible, otherwise be sure to enable it on the container view that give you poor performances).

Quoting Apple docs:

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:

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:

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."

More on: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/SettingUpLayerObjects/SettingUpLayerObjects.html

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

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