8

如果我们NSTrackingArea用于某些指定区域,那么我们可以实现这样的方法来更改默认光标:

-(void)cursorUpdate:(NSEvent *)theEvent {
    [[NSCursor resizeLeftCursor] set];
}

我为 实现自定义调整大小NSWindow,它使用NSBorderlessWindowMask. 并且想使用原生 Lion 的两个箭头游标。但是NSCursor API中不存在这种类型的游标。

我可以从代码中以某种方式获得这样的本机游标吗?
或者也许我必须手动重新绘制它们(不是一个好主意)?

4

4 回答 4

15

不幸的是,WebKit 中存在的那些在视网膜分辨率中不可用,查看

/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors

你会发现调整光标大小的 pdf 版本。

于 2012-10-25T09:06:47.847 回答
6

下面是一些示例代码,用于从 HIServices.framework 加载基于矢量(因此支持视网膜)的游标:

NSString *cursorName = @"resizenortheastsouthwest";
NSString *cursorPath = [@"/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors" stringByAppendingPathComponent:cursorName];
NSImage *image = [[NSImage alloc] initByReferencingFile:[cursorPath stringByAppendingPathComponent:@"cursor.pdf"]];
NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[cursorPath stringByAppendingPathComponent:@"info.plist"]];
NSCursor *cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint([[info valueForKey:@"hotx"] doubleValue], [[info valueForKey:@"hoty"] doubleValue])];

注意我不知道这是否适用于沙盒应用程序。

于 2014-02-14T18:27:27.993 回答
4

有创建此类游标的未记录方法。这是一个例子:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
    if ([NSCursor respondsToSelector:@selector(_windowResizeNorthSouthCursor)])
    {
        self.resizeUpDownCursor = [NSCursor performSelector:@selector(_windowResizeNorthSouthCursor)];
    }
    else
    {
        self.resizeUpDownCursor = [NSCursor resizeUpDownCursor];
    }
#pragma clang diagnostic pop

以下是 macOS Sierra 中未记录光标的完整列表:

[NSCursor _windowResizeEastCursor]
[NSCursor _windowResizeWestCursor]
[NSCursor _windowResizeEastWestCursor]
[NSCursor _windowResizeNorthCursor]
[NSCursor _windowResizeSouthCursor]
[NSCursor _windowResizeNorthSouthCursor]
[NSCursor _windowResizeNorthEastCursor]
[NSCursor _windowResizeNorthWestCursor]
[NSCursor _windowResizeSouthEastCursor]
[NSCursor _windowResizeSouthWestCursor]
[NSCursor _windowResizeNorthEastSouthWestCursor]
[NSCursor _windowResizeNorthWestSouthEastCursor]
[NSCursor _zoomInCursor]
[NSCursor _zoomOutCursor]
[NSCursor _helpCursor]
[NSCursor _copyDragCursor]
[NSCursor _genericDragCursor]
[NSCursor _handCursor]
[NSCursor _closedHandCursor]
[NSCursor _moveCursor]
[NSCursor _waitCursor]
[NSCursor _crosshairCursor]
[NSCursor _horizontalResizeCursor]
[NSCursor _verticalResizeCursor]
[NSCursor _bottomLeftResizeCursor]
[NSCursor _topLeftResizeCursor]
[NSCursor _bottomRightResizeCursor]
[NSCursor _topRightResizeCursor]
[NSCursor _resizeLeftCursor]
[NSCursor _resizeRightCursor]
[NSCursor _resizeLeftRightCursor]
于 2017-10-08T19:51:55.500 回答
1

WebKit 包含看起来与系统使用的光标完全相同的图像,位于以下目录中:

/System/Library/Frameworks/WebKit.framework/Versions/Current/Frameworks/WebCore.framework/Resources/

...例如,文件“northWestSouthEastResizeCursor.png”。

于 2012-06-25T07:53:34.203 回答