setIgnoresMouseEvents:YES不工作(例如闪烁窗口)

时间:2011-03-18 03:39:30

标签: objective-c cocoa macos

我认为我的问题最好在视频中说明:http://cl.ly/5Iou

基本上,我在我的窗口中创建了一个跟踪区域:

NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[self frame] options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways owner:self userInfo:nil];
[self addTrackingArea:area];
[area release];

然后我实施了:

-(void)mouseEntered:(NSEvent *)event {
    [self toggleDetail];
}
-(void)mouseExited:(NSEvent *)event {
    [self toggleDetail];
}

awakeFromNib我说了这个:

[attachedWindow setIgnoresMouseEvents:YES];

toggleDetail看起来有点类似:(弹出窗口是MAAttachedWindow

- (void)toggleDetail {
    if (!attachedWindow) {
        NSPoint buttonPoint = NSMakePoint(NSMidX([conditionImage frame]),
                                          NSMidY([conditionImage frame]));
        attachedWindow = [[MAAttachedWindow alloc] initWithView:view 
                                                attachedToPoint:buttonPoint 
                                                       inWindow:[self window] 
                                                         onSide:12
                                                     atDistance:65.0];
        //irrelevant window setup here
        [[self window] addChildWindow:attachedWindow ordered:NSWindowAbove];
    } 
    else {
        [[self window] removeChildWindow:attachedWindow];
        [attachedWindow orderOut:self];
        [attachedWindow release];
        attachedWindow = nil;
    }
}

因此,正如您在视频中看到的那样,如果我将鼠标移到远离窗口的窗口上,然后将其移动到弹出窗口上,则不会发生“脉冲”。但是,如果我将鼠标移动到将出现弹出窗口的一般附近,然后将鼠标移动到窗口中,它会发出脉冲。几乎看起来窗口没有时间注册它不应该接收鼠标事件。有任何想法吗?为了解决这个问题,我已经达成了我的智慧。

1 个答案:

答案 0 :(得分:2)

哇,这很简单。我刚想通了。我在说这个:

[attachedWindow setIgnoresMouseEvents:YES];
在窗口初始化之前

。因此它没有因某种原因而注册。所以,我把它移到了这里:

//in toggleDetail
attachedWindow = [[MAAttachedWindow alloc] initWithView:view 
                                            attachedToPoint:buttonPoint 
                                                   inWindow:[self window] 
                                                     onSide:12
                                                 atDistance:65.0];
[attachedWindow setIgnoresMouseEvents:YES]; //HERE it works!
[[self window] addChildWindow:attachedWindow ordered:NSWindowAbove];

所以,在它初始化之后,就在它显示之前。最后它正在运作! :)