NSCursor正在消失的ItemCursor并没有停留在窗外

时间:2013-09-25 22:37:15

标签: objective-c cocoa drag-and-drop nstableview nscursor

我有一个包含NSTableView的弹出式状态栏应用程序。当一行被拖到表外时(拖放完全在这里工作,这不是问题的焦点)我将光标更改为poofy-pointer,也称为[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];
        }
    }
}

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




更新
我还尝试了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];
            }
        }
    }
}




更新
我也尝试使用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;
}

0 个答案:

没有答案