NSScrollView 作为层支持视图的子视图错误?
当我将 NSScrollView 作为层支持视图的子视图(例如,通过从 IB 选择 NSTextView 或 NSTableView)时,我在滚动视图的文档视图中看到奇怪的绘图行为。
为了说明这一点,我在窗口中创建了一个带有 NSTextView 的简单项目。我编写的唯一代码是打开窗口内容视图的图层支持:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[self.window contentView] setWantsLayer:YES];
}
这是我在文本视图中键入内容时的结果。红色下划线未正确排列:
http://mowglii.com/random/screenshot.png< /a>
此外,当我调整文本视图大小时,文本和下划线抖动很多。当我使用表格视图(滚动视图内)而不是文本视图时,我在调整大小时看到了相同的抖动。
知道发生了什么事吗?
When I make an NSScrollView a subview of a layer-backed view (for example by choosing an NSTextView or NSTableView from IB), I see strange drawing behavior in the scroll view's document view.
To illustrate, I created a simple project with an NSTextView in a window. The only code I wrote is to turn on layer-backing for the window's content view:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[self.window contentView] setWantsLayer:YES];
}
This is the result when I type into the textview. The red underlines don't line up properly:
http://mowglii.com/random/screenshot.png
Also, the text and underlines jitter a lot when I resize the textview. I've seen the same jitter on resize when I use a tableview (inside a scrollview) instead of a textview.
Any idea what is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当嵌入到层支持的视图中时,NSScrollView 确实表现得很糟糕。
需要一些严重的技巧来对包含滚动视图的视图进行动画处理。您可以尝试仅在需要制作动画时才打开图层支持。然后,您需要强制绘图,以免最终出现空层。
然而,通常情况下,您需要更深入地了解技巧的背后。即:保持图层支持关闭。将视图绘制到图像中,在启用了图层支持的覆盖视图中显示该图像。将该视图动画化为最终状态的图像。然后删除覆盖视图以显示下面的实际最终状态。
NSScrollView indeed misbehaves badly when embedded in a layer-backed view.
Some serious trickery is needed to animate views containing scroll views. You could try turning on layer-backing only once you need to animate. You then need to force the drawing in order not to end up with an empty layer.
Usually, you will however need to go look much deeper in the back of tricks. Namely: Keep layer-backing switched off. Draw the view into an image, display that image in an overlay view with layer-backing enabled. Animate that view to an image of the final state. Then remove the overlay view to reveal the actual final state below.