我有一个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
)会垂直翻转!有什么想法吗?