gpt4 book ai didi

objective-c - 为什么跟踪区域不受尊重

转载 作者:行者123 更新时间:2023-12-03 17:14:47 26 4
gpt4 key购买 nike

我一直在尝试跟踪区域,并且遇到了一些问题,所以我创建了这个简单的程序作为测试。我在 View 的左下角(即窗口的内容 View )创建一个跟踪区域,但无论我在何处进入或退出 View ,我都会收到 mouseEntered 和 exited 消息。我还尝试将此代码放入 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

为什么不遵守跟踪区域?

最佳答案

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

options:NSTrackingActiveAlways | NSTrackingMouseEnteredAndExited

关于objective-c - 为什么跟踪区域不受尊重,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10004156/

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