Change mouse cursor over inactive NSWindow

前端 未结 3 1091
醉梦人生
醉梦人生 2020-12-16 06:02

I have subclassed NSWindow and I have a MYWindow class implementing the following method:

-(void)resetCursorRects {
    NSImage *image = [NSImage imageNamed:         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-16 06:19

    You should be able to add an NSTrackingArea that changes the cursor, as long as you don’t want it to also change when the app is inactive (that is essentially impossible).


    Edit:

    I was able to get this working with the following code:

    - (vod)someSetup;
    {
        NSTrackingArea *const trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options: (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect) owner:self userInfo:nil];
        [self.view addTrackingArea:trackingArea];
    }
    
    - (void)mouseEntered:(NSEvent *)theEvent;
    {
        [[NSCursor IBeamCursor] push];
    }
    
    - (void)mouseExited:(NSEvent *)theEvent;
    {
        [[NSCursor IBeamCursor] pop];
    }
    

提交回复
热议问题