1

我一直在尝试跟踪区域,并且遇到了一些问题,所以我创建了这个简单的程序作为测试。我在视图的左下角创建了一个跟踪区域(这是窗口的内容视图),但是mouseEntered无论我在哪里进入或退出视图,我都会收到和退出消息。我也试过把这段代码放在 init 方法中并awakeFromNib得到相同的结果。

@implementation Parent //This view is the contentView of the main window

-(void)viewDidMoveToWindow{
    NSLog(@"In viwDidMoveToWindow");
    NSTrackingArea *area = [[NSTrackingArea alloc]initWithRect:NSMakeRect(0,0,50,50) options:NSTrackingInVisibleRect |NSTrackingMouseEnteredAndExited |NSTrackingActiveInActiveApp owner:self userInfo:nil];
    [self addTrackingArea:area];
}

-(void)mouseEntered:(NSEvent *)theEvent {
    NSLog(@"Entered");
}

-(void)mouseExited:(NSEvent *)theEvent {
    NSLog(@"Exited");
}

@end

为什么不尊重跟踪区域?

4

1 回答 1

1

它与您正在使用的选项有关,请尝试使用

options:NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited
于 2012-04-04T04:02:30.950 回答