Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSCursor always resets to Arrow

Why can't I get the cursor to stay put for the duration of my mouse drag? As soon as I start dragging, it reverts to "Arrow" (even though I set it as open hand in the app delegate after launch).

- (void)mouseDown:(NSEvent *)event
{
   [[NSCursor closedHandCursor] push];
}

- (void)mouseUp:(NSEvent *)event
{
   [NSCursor pop];
}
like image 506
borrrden Avatar asked Jul 02 '12 03:07

borrrden


2 Answers

If you don't want other views to change your cursor while dragging you can do in -mouseDown:

[[self window] disableCursorRects];

and in -mouseUp:

[[self window] enableCursorRects];
[[self window] resetCursorRects];
like image 53
Yoav Avatar answered Oct 22 '22 16:10

Yoav


Try using the addCursorRect:cursor: to set the cursor for you view.

Override the resetCursorRects for your view:

- (void)resetCursorRects
{
    [super resetCursorRects];
    if(drag) {
        [self addCursorRect:self.bounds cursor:[NSCursor closedHandCursor]];
    }
}

You need to call invalidateCursorRectsForView: to force update your cursor rects:

[self.window invalidateCursorRectsForView:self];

But if you want to have different cursor outside of you view you can call [[NSCursor closedHandCursor] set] in your mouseDragged: method.

like image 12
Dmitry Avatar answered Oct 22 '22 17:10

Dmitry