resetCursorRects not working (new cursor only flashes as mouse enters)
Asked Answered
E

2

2

I'm creating a custom view that needs a special cursor (instead of the usual arrow). I'm using the resetCursorRects to setup the new cursor and its area, but the new cursor only appears briefly when the mouse enters the rect area, returning to arrow.

To check things better, I've created a new project, create a new custom view (based on NSView), add it to the window, but the problem remains. The custom view code:

#import "TestView.h"

@implementation TestView

- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];

    [[NSColor redColor]set];
    [NSBezierPath fillRect:self.bounds];
}

-(void)resetCursorRects
{
    [self addCursorRect:NSMakeRect(2, 2, 40, 40) cursor:[NSCursor openHandCursor]];
}

@end

I've tried things like [super resetCursorRects] or [self discardCursorRects] before the addCursorRect, but nothings happens. Am I doing anything wrong?

Embellishment answered 4/8, 2015 at 18:12 Comment(0)
W
1

Your code is correct and seems to work pretty fine in all cases.

There are some additional methods to set cursor image. Maybe they help you, 2 examples below.

1) You can set tracking area in your custom View and use NSResponder cursorUpdate: method in that view. Something like that:

// call when initializing view
- (void)updateTrackingAreas {
    [[NSTrackingArea alloc] initWithRect:self.visibleRect options: (NSTrackingCursorUpdate | NSTrackingEnabledDuringMouseDrag | NSTrackingActiveInActiveApp) owner:self userInfo:nil];
}

// NSResponder override in view
- (void)cursorUpdate:(NSEvent *)event {
    [[NSCursor openHandCursor] set];
}

2) If you are using your custom View in ScrollView you can use setDocumentCursor: method of ScrollView:

[self.scrollView setDocumentCursor:[NSCursor openHandCursor]];
Wrand answered 5/8, 2015 at 7:57 Comment(0)
E
0

Solved with a reboot... After many hours of work, I discovered it was some sort of bug from the system, which was solved by a simple reboot.

Thank you all for your time...

Embellishment answered 6/8, 2015 at 9:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.