【发布时间】:2011-10-25 12:41:27
【问题描述】:
为了在按钮上创建翻转效果,我创建了一个名为 Button 的 NSButton 子类。
按钮.h:
#import <AppKit/AppKit.h>
@interface Button : NSButton {
}
- (void)mouseEntered:(NSEvent *)theEvent;
- (void)mouseExited:(NSEvent *)theEvent;
- (void)mouseDown:(NSEvent *)ev;
- (void)mouseUp:(NSEvent *)theEvent;
@end
按钮.m: #import "Button.h"
@implementation Button
- (id)initWithFrame:(NSRect)frameRect {
self = [super initWithFrame:frameRect];
if(self != nil) {
NSLog(@"btn init");
}
return self;
}
- (void)mouseEntered:(NSEvent *)theEvent{
NSLog(@"mouseEntered");
[self setImage:[NSImage imageNamed:@"lockIcon_2.png"]];
[self setNeedsDisplay];
}
- (void)mouseExited:(NSEvent *)theEvent{
[self setImage:[NSImage imageNamed:@"lockIcon_1.png"]];
NSLog(@"mouseExited");
[self setNeedsDisplay];
}
- (void)mouseDown:(NSEvent *)ev {
NSLog(@"mouseDown!");
}
- (void)mouseUp:(NSEvent *)ev {
NSLog(@"mouseUp!");
}
@end
使用上面的代码,每次单击按钮时,我都会在日志中看到“mouseDown”,但看不到“mouseEntered”或“mouseExited”(当然也看不到图像更改)? ?可悲的是,我知道我遗漏了一些明显的东西,但我只是没有看到它...... ???
【问题讨论】:
标签: objective-c cocoa