在我的应用程序委托中,我创建了一个窗口“helpWindow”,并将其内容视图设置为 NSView 子类。在我的子类中,我 drawRect 并确保它是关键窗口。我遇到的问题是,在我的鼠标事件中,鼠标按下事件与内容视图一起正常工作,但是,移动的鼠标不起作用并显示位置。我必须添加一些东西mouseLocation
吗?我觉得drawRect掩盖了鼠标移动事件。谢谢!
//在我的 appDelegate.m
controlFilterBox = [[MoveFilter alloc] initWithFrame:helpWindow.frame];
[helpWindow setContentView:controlFilterBox];
[controlFilterBox release];
//在我的 NSView subclass.m
-(void)drawRect:(NSRect)dirtyRect
{
[[NSColor redColor] set];
NSRectFill(dirtyRect);
[[self window] makeKeyWindow];
}
-(void)mouseDown:(NSEvent *)theEvent
{
NSPoint eventLocation = [theEvent locationInWindow];
NSPoint location = [self convertPoint:eventLocation fromView:nil];
NSLog(@"exit %f %f", location.x, location.y);
}
-(void)mouseMoved:(NSEvent *)theEvent
{
NSPoint mouseLoc = [NSEvent mouseLocation];
NSLog(@"mouseMoved: %f %f", mouseLoc.x, mouseLoc.y);
}