Objective c NSCursor';s IssubearingItemCursor未在窗口外设置
我有一个弹出式状态栏应用程序,其中包含一个Objective c NSCursor';s IssubearingItemCursor未在窗口外设置,objective-c,cocoa,drag-and-drop,nstableview,nscursor,Objective C,Cocoa,Drag And Drop,Nstableview,Nscursor,我有一个弹出式状态栏应用程序,其中包含一个NSTableView。当一行被拖到表外时(拖放在这里完全起作用,这不是问题的焦点),我将光标更改为poofy指针,否则称为[NSCursor descouringitemcursor]如下: - (void)draggingSession:(NSDraggingSession *)session movedToPoint:(NSPoint)screenPoint { if (self.draggedRowCanBeDeleted) {
NSTableView
。当一行被拖到表外时(拖放在这里完全起作用,这不是问题的焦点),我将光标更改为poofy指针,否则称为[NSCursor descouringitemcursor]
如下:
- (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;
}
当指针在外部时,您是否尝试过使用
[[NSCursor discosearingitemcursor]push]
,如果指针光标在外部而不再存在,是否尝试过使用[NSCursor pop]
?也就是说,当指针第一次移动到窗口外时,您会推动消失的项目光标,如果指针移回窗口或拖动被取消,则会弹出到原始光标,以确保每次推动都与弹出平衡。不幸的是,当使用push/pop与set/set时,会显示出相同的行为。这不是一种替代方法,它是一种使其工作的方法,正如我前面指定的那样,确实可以工作。这里的问题是关于不可靠的游标poof。我已经更新了一些代码