NSCursor: “set” method has no effect

半城伤御伤魂 提交于 2019-12-06 08:39:57

I know it has been awhile. But I had a similar problem.

For some reason [cursor set] doesn't work when being called from the application events.

Here is how I did it:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [self performSelector:@selector(doChangeCursor) withObject:nil afterDelay:1];
}

- (void) doChangeCursor
{
    NSString *file = [[NSBundle mainBundle] pathForResource:@"statusBarImage" ofType:@"tiff"];
    NSImage *image = [[NSImage alloc] initWithContentsOfFile:file];
    NSCursor *cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(0, 0)];
    [cursor set];    
}

I hope this is able to help someone.

Working solution for me to change the cursor from system event was to wrap the cursor set inside async like so:

DispatchQueue.main.async {
    self.customCursor.set()
}

(Swift 3)

Well, I could not find any solution to this problem. I had to use a workaround: handle a sprite cursor set at the position of the cursor...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!