gpt4 book ai didi

macos - NSImage 与 NSValueTransformer 一起使用时具有不透明度

转载 作者:行者123 更新时间:2023-12-03 16:06:19 24 4
gpt4 key购买 nike

我试图根据核心数据中的枚举值来显示 NSImage。我在绑定(bind)到我所使用的值的 NSImageCell 上使用值转换器选择要显示的图像。

它工作完美并且符合预期,不幸的是,当使用 NSValueTransformer 时,图像获得了不应该具有的不透明度。

这是我的 NSValueTransformer 子类的摘录:

+ (void)initialize
{
downloadingImage = [NSImage imageNamed:@"downloading.png"];
downloadFailedImage = [NSImage imageNamed:@"download_failed.png"];
downloadCompleteImage = [NSImage imageNamed:@"download_complete.png"];
}
+ (Class)transformedValueClass { return [NSImage class]; }
+ (BOOL)allowsReverseTransformation { return NO; }
- (id)transformedValue:(id)value {
switch([value intValue])
{
case DownloadStatusComplete:
return downloadCompleteImage;
case DownloadStatusFailed:
return downloadFailedImage;
case DownloadStatusNone:
return nil;
case DownloadStatusDownloading:
return downloadingImage;
default:
return nil;
}
}

对应的静态NSImage定义:

static NSImage* downloadingImage;
static NSImage* downloadFailedImage;
static NSImage* downloadCompleteImage;

以及我使用的枚举:

typedef enum {
DownloadStatusNone,
DownloadStatusDownloading,
DownloadStatusComplete,
DownloadStatusFailed
} DownloadStatus;

下面是实际应用程序的屏幕截图,其中没有 NSValueTransformer,但在 IB 中分配了静态 NSImage。所以 PNG 并不是有 alpha 之类的。来自不同位置的三张不同图像会发生这种情况。

actual application http://imageshack.us/a/img195/2492/appqe.png static image http://imageshack.us/a/img27/3289/43084671.png

最佳答案

亚琛 cocoaheads 的一位成员向我指出:Why are my images in my NSTableView faded out?

From Jim Correia on Cocoa-Dev:

"On 10.6, NSImageView will draw its content as dimmed when the control is disabled.

Your binding has “Conditionally Sets Enabled” turned on."

这为我解决了这个问题!

关于macos - NSImage 与 NSValueTransformer 一起使用时具有不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17022751/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com