带有CALayer的NSButton在单击时会翻转图像

时间:2014-01-02 12:06:28

标签: objective-c calayer

我有一个NSButton附加了CALayer并在其上设置了图片。当我点击按钮时,图像会翻转!

_zoomButton = [NSButton new];
[_zoomButton setBordered:NO];
[_zoomButton setButtonType:NSMomentaryChangeButton];
[_zoomButton setTitle:@""];
[_zoomButton setWantsLayer:YES];
[_zoomButton setImage:s_zoomImage];
[_zoomButton sizeToFit];

s_zoomImage只是从资源加载的NSImage:

namespace
{
    NSImage *s_zoomImage; // No static variables in Objective-C.
}

+ (void)initialize
{
    [super initialize];

    NSString *const zoomImagePath = [[NSBundle mainBundle] pathForResource:@"Zoom.png" ofType:nil];
    s_zoomImage = [[[NSImage alloc] initWithContentsOfFile:zoomImagePath] autorelease];
}

首先按钮显示正确,但如果我点击它,图像(s_zoomImage)会垂直翻转!有什么想法吗?

0 个答案:

没有答案