2
在我的应用程序委托中,我创建了一个窗口“helpWindow”,并将其内容视图设置为一个NSView子类。在我的子类drawRect并确保它的关键窗口。我遇到的问题是,在我的鼠标事件中,鼠标按下事件与内容视图无关,但是,鼠标移动不起作用并显示位置。我必须添加一些东西到mouseLocation
?我觉得drawRect覆盖了鼠标移动的事件。谢谢!NSView的mouseMoved事件
//我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);
}