gpt4 book ai didi

objective-c - setIgnoresMouseEvents :YES not working (e. g。闪烁窗口)

转载 作者:行者123 更新时间:2023-12-03 17:43:30 25 4
gpt4 key购买 nike

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

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

最佳答案

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

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

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

关于objective-c - setIgnoresMouseEvents :YES not working (e. g。闪烁窗口),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5347810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com