NSCursor的missingingItemCursor不在窗口外部设置

con*_*are 5 cocoa drag-and-drop objective-c nstableview nscursor

我有一个包含状态的弹出状态栏应用程序NSTableView。当将一行拖到表外时(拖放在这里完全起作用,这不是问题的重点),我将光标更改为the指针,否则称为[NSCursor disappearingItemCursor]

- (void)draggingSession:(NSDraggingSession *)session movedToPoint:(NSPoint)screenPoint {
    if (self.draggedRowCanBeDeleted) {
        BOOL outside = !NSPointInRect(screenPoint, window.frame);
        if (outside) {
            [[NSCursor disappearingItemCursor] set];
        } else {
            [[NSCursor arrowCursor] set];
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是非常不可靠的,因为有时它有时不起作用。它通常在第一次尝试时起作用,但是在此之后退出工作。我似乎找不到我要拖动的东西或拖动行进多远等的模式,只是看起来很不稳定。我在这里做错什么了吗?如果没有,我可以做些什么来帮助诊断问题吗?




更新
我也尝试了push/ pop路由,问题仍然存在。

- (void)draggingSession:(NSDraggingSession *)session movedToPoint:(NSPoint)screenPoint {
    if (self.draggedRowCanBeDeleted) {
        BOOL outside = !NSPointInRect(screenPoint, window.frame);
        if (outside) {
            if (!_showingPoof) {
                _showingPoof = YES;
                [[NSCursor disappearingItemCursor] push];
            }
        } else {
            if (_showingPoof) {
                _showingPoof = NO;
                [[NSCursor disappearingItemCursor] pop];
                // I have also tried: [NSCursor pop];
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)




更新
我也尝试过使用该sourceOperationMaskForDraggingContext方法来设置它。我可以确认在正确的时间调用了正确的段,但是在执行此路线时,光标永远不会改变。

- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
    if (self.draggedRowCanBeDeleted) {
        switch(context) {
            case NSDraggingContextOutsideApplication:
                [[NSCursor disappearingItemCursor] set];
                return NSDragOperationDelete;
                break;

            case NSDraggingContextWithinApplication:
                [[NSCursor closedHandCursor] set];
                return NSDragOperationMove;

            default:
                [[NSCursor arrowCursor] set];
                return NSDragOperationNone;
        }
    }

    return NSDragOperationNone;
}
Run Code Online (Sandbox Code Playgroud)