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

发布于 2024-10-22 08:40:59 字数 1775 浏览 0 评论 0原文

我认为我的问题最好在视频中描述: 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;
    }
}

因此,正如您在视频中看到的,如果我将鼠标移到窗口上远离窗口,然后将其移到弹出窗口上,则不会发生“脉冲”。但是,如果我将鼠标移到弹出窗口将出现的大致区域,然后将鼠标移到窗口中,它就会发出脉冲。看起来窗口几乎没有时间注册它不应该接收鼠标事件。有什么想法吗?我已经无计可施,试图解决这个问题。

I think my problem can best be described in a video: http://cl.ly/5Iou

Basically, I'm creating a tracking area in my window like this:

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

Then I've implemented:

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

And in awakeFromNib I put this:

[attachedWindow setIgnoresMouseEvents:YES];

toggleDetail looks somewhat similar to this: (the popup is a 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;
    }
}

So, as you can see in the video, the "pulsing" doesn't happen if I move my mouse over the window away from the window, then move it over the popup window. However, if I move my mouse over the general vicinity where the popup window will appear, then move my mouse into the window, it pulses. It almost seems like the window doesn't have time to register that it shouldn't receive mouse events. Any ideas? I've reached my wits ends trying to work around this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一影成城 2024-10-29 08:40:59

哇,那很简单。我刚刚想通了。我正在调用这个:

[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];

所以,就在它初始化之后,但就在它显示之前。终于可以工作了! :)

Wow, that was simple. I just figured it out. I was calling this:

[attachedWindow setIgnoresMouseEvents:YES];

before the window had initialized. Thus it didn't register for some reason. So, I moved it here:

//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];

So, right after it's initialized, but right before it's displayed. Finally it's working! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文