0
基本上,我想要一個覆蓋整個屏幕的「隱形」NSView。我將添加一個NSTrackingArea,以便在光標在屏幕上移動時獲取全局鼠標事件。在未連接到窗口的NSView中使用NSTrackingArea?
-(void)setTrackingArea
{
view = [[NSView alloc] initWithFrame:[NSScreen currentScreenForPoint:[NSEvent mouseLocation]].frame];
NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[NSScreen currentScreenForPoint:[NSEvent mouseLocation]].frame options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways owner:view userInfo:nil];
[view addTrackingArea:area];
[area release];
//[[window contentView] addSubview:view];
//I don't want to add the view to a window, as all tutorials say.
}
- (void)mouseExited:(NSEvent *)theEvent
{
NSLog(@"Exit"); //Never firing
}
這可能嗎?使用NSViews和NSTracking區域沒有窗口?
你不能有一個觀點,這不是在一個窗口,但你應該能夠創建一個不可見的窗口涵蓋整個屏幕。 – 2012-03-27 08:29:30