如何放置NSButton在NSTableView [英] How to place an NSButton over an NSTableView

查看:361
本文介绍了如何放置NSButton在NSTableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





1)没有按钮后面的表
2)加载的表
3)滚动后



如果我在NSTableView上放置一个按钮,我在滚动后留下的工件。有没有人知道如何解决这个问题?



我目前的解决方案只是将表中的部分拆分为2.下部是一个禁用的按钮在后台。 / p>

解决方案

这是因为滚动视图设置为在滚动时复制其内容,并且只重绘新露出的部分作为性能优化。要关闭它,请使用

  myTableView.enclosingScrollView.contentView.copiesOnScroll = 

虽然这将使滚动使用更多的CPU(你也可以在XIB,



可能更好的方法是将滚动视图和按钮切换为layer-backed:

  myTableView.enclosingScrollView.wantsLayer = YES; 
myButtonView.wantsLayer = YES;

(同样,您可以在XIB文件的Layers检查器中设置,单击每个视图旁边的复选框以给它一个图层)现在,滚动视图将只从其自己的图层(不再包括您的按钮)复制的东西。此外,现在所有的文本视图的合成将使用在显卡。但是,如果你把文本放在透明的背景上(例如,如果你有一个带有标题的透明按钮),你会失去子像素抗锯齿。


1) No table behind button 2) Table loaded 3) After scrolling

If I place a button over an NSTableView I get artifacts being left behind after scrolling. Does anyone know how to fix this?

My current solution is just to split the section with the table into 2. The lower portion is a disabled button in the background.

解决方案

That's because the scroll view is set to copy its contents when scrolling and only redraw the newly-uncovered part as a performance optimization. To turn that off, use

myTableView.enclosingScrollView.contentView.copiesOnScroll = NO;

though that will make scrolling use more CPU (you can also do this in the XIB, look for a 'copies on scroll' checkbox).

Probably a better approach would be to switch the scroll view and the button to be layer-backed:

myTableView.enclosingScrollView.wantsLayer = YES;
myButtonView.wantsLayer = YES;

(Again, you can set this in the 'Layers' inspector of the XIB file, where you can click a checkbox next to each view to give it a layer) Now, the scroll view will only copy stuff from its own layer (which no longer includes your button). Also, now all the compositing of the text view will be done using in the graphics card. This works fine with an opaque push button, however, if you put text on a transparent background in its own layer (e.g. if you have a transparent pushbutton with a title), you lose sub-pixel anti-aliasing.

这篇关于如何放置NSButton在NSTableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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