highlightSelectionInClipRect

highlightSelectionInClipRect

本文介绍了基于视图的NSOutlineview选择渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然在我的小Cocoa应用程序中努力与基于视图的NSOutlineView。我试图模型我的OutlineView后finder一。当Finder OutlineView失去焦点(例如点击右侧的任何文件夹)时,所选行(例如桌面)将保持以明亮的蓝色渐变选择,并且不会更改为无效的蓝灰色渐变。



我想在我的应用程序中复制此行为。



在一个不基于视图的OutlineView中,我能够子类化NSOutlineView并重新实现(void)highlightSelectionInClipRect:(NSRect)clipRect ,使得可以向每个突出的行提供亮蓝色背景图像。



然而,现在我的基于视图的OutlineView(设置为SourceList样式),这个方法显然甚至没有被调用。我甚至实现(id)_highlightColorForCell:(NSCell *)cell 返回nil,如一些网站建议,但这也没有帮助。



有关如何在基于视图的OutlineView中设置高亮度渐变的任何提示?

解决方案

你在做任何自定义绘图,可能会弄乱的事情吗?就我可以告诉所有的选择绘图是正常处理,请查看(默认情况下不是源列表样式,但这是对XIB的一个简单更改)。



但是,根据Mac OS X 10.7 doc条目 highlightSelectionInClipRect:

所以我想(我没有尝试任何这个)像你想要子类化NSTableRowView,重写 drawSelectionInRect:(有一个 [NSApp active] 来检查应用程序是否处于活动状态,然后在TableViewPlayground中创建一个示例代码/ TableViewPlayground / Listings / ATSampleWindowRowView_m.html或者使用 self.emphasized 属性。



然后你会返回一个自定义NSTableRowViews在NSOutlineViewDelegate协议方法(10.7 only!):(NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item



希望这有效/帮助!



我应该注意,TableViewPlayground示例使用 outlineView:viewForTableColumn:item:委托方法默认情况下,并执行一切与NSTableViewCells,但如果你添加 rowViewForItem 方法我上面提到它是调用。所以我猜你可以使用它返回一个视图的每一行在其整体。


I'm still struggling with the view-based NSOutlineView in my little Cocoa application. I'm trying model my OutlineView after the finder one. When the Finder OutlineView loses focus (e.g. clicking any folder on the right side), the selected row (e.g. Desktop) stays selected with the bright blue gradient and does not change to the inactive blue-grey gradient.

I'd like to duplicate this behaviour in my application.

In a not view-based OutlineView I was able to subclass NSOutlineView and reimplement (void)highlightSelectionInClipRect:(NSRect)clipRect, so that each highlighted row could be supplied with the bright blue background image.

However, now with my view-based OutlineView (set to SourceList style) this method apparently is not even called. I've even implemented (id)_highlightColorForCell:(NSCell *)cell to return nil, as some sites suggest, but that doesn't help either.

Any hints on how I can set the highlight gradient in the view-based OutlineView?

解决方案

Are you doing any custom drawing that could be messing with things? As far as I can tell all the selection drawing is handled for you normally, check out the TableViewPlayground example (not Source-list style by default but that's an easy change to the XIB).

But failing that, according to the Mac OS X 10.7 doc entry on highlightSelectionInClipRect:

So I think (I haven't tried any of this) like you'd want to subclass NSTableRowView, override drawSelectionInRect: (there's an example in TableViewPlayground, and draw your selection. You could check for the app being active with [NSApp active] or maybe use the self.emphasized property like the example does.

You'd then return one of your custom NSTableRowViews in the NSOutlineViewDelegate protocol method (10.7 only!): (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item

Hope this works/helps!

I should note that TableViewPlayground example uses the outlineView:viewForTableColumn:item: delegate method by default and does everything with NSTableViewCells, but if you add the rowViewForItem method I mention above it is called. So I'm guessing you could use it to return a view for each row in it's entirety.

这篇关于基于视图的NSOutlineview选择渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 21:02