Objective c 调整NSTableView拖动会话的坐标

Objective c 调整NSTableView拖动会话的坐标,objective-c,macos,cocoa,nstableview,Objective C,Macos,Cocoa,Nstableview,我已经绞尽脑汁两周了,我查看了所有可用的苹果文档以及数百个网站,寻找解决我问题的提示。我正在实施: -(void)tableView:(NSTableView *)tableView draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint)screenPoint forRowIndexes:(NSIndexSet *)rowIndexes 我遇到的问题是,被拖动文件的图标显示在不同的坐标系中,我似乎找不到方法

我已经绞尽脑汁两周了,我查看了所有可用的苹果文档以及数百个网站,寻找解决我问题的提示。我正在实施:

-(void)tableView:(NSTableView *)tableView draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint)screenPoint forRowIndexes:(NSIndexSet *)rowIndexes
我遇到的问题是,被拖动文件的图标显示在不同的坐标系中,我似乎找不到方法使图标显示在拖动开始的屏幕点上。我研究了所有[tableView convert*]方法的几种组合,但没有成功。下面是我目前使用的代码

-(void)tableView:(NSTableView *)tableView draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint)screenPoint forRowIndexes:(NSIndexSet *)rowIndexes {

[session enumerateDraggingItemsWithOptions:NSDraggingItemEnumerationConcurrent
                                   forView:tableView
                                   classes:[NSArray arrayWithObjects:[NSPasteboardItem class], nil]
                             searchOptions:nil
                                usingBlock:^(NSDraggingItem *draggingItem, NSInteger index, BOOL *stop)
 {
     NSMutableArray *videos = [NSMutableArray array];
     for (Video* video in [_arrayController selectedObjects]) {
         [videos addObject:video.url];
     }

     NSImage *draggedImage = [[NSWorkspace sharedWorkspace]iconForFiles:videos];
     NSPoint mouseLocInView = [tableView convertPoint:[tableView.window convertRectFromScreen:NSMakeRect(screenPoint.x,screenPoint.y, 0, 0)].origin fromView:nil];

     NSLog(@"Mouse location in view: X: %f, Y: %f",mouseLocInView.x, mouseLocInView.y);
     NSLog(@"Screen point: X: %f, Y:%f", screenPoint.x, screenPoint.y);

     NSRect rect = NSMakeRect(0, 0, 50, 50);
     rect.origin =draggingItem.draggingFrame.origin;
     [draggingItem setDraggingFrame:rect contents:draggedImage];
     session.draggingFormation = NSDraggingFormationDefault;
 }];}

在彻底阅读了文档之后,我终于得到了它

医生 -EnumeratedraggingItemsWithoOptions:forView:classes:searchOptions:usingBlock:表示forView:参数是传递的每个NSDragingItem的坐标系应基于的视图。屏幕坐标系通过零

最让人困惑的是,我在调试draggingItem时记录了draggingFrame,但无法确定它是什么帧。不管里面有什么,如果你把nil作为一个视图传递,你可以把拖动框设置为基于屏幕的坐标,这和你调用session.draggingLocation时得到的一样

#define DRAG_IMAGE_WIDTH 48
#define DRAG_IMAGE_HEIGHT 48

- (void)tableView:(NSTableView *)tableView
  draggingSession:(NSDraggingSession *)session
 willBeginAtPoint:(NSPoint)screenPoint
    forRowIndexes:(NSIndexSet *)rowIndexes {

    NSImage *image = [NSImage imageNamed:@"tunnelfile"];

    [session enumerateDraggingItemsWithOptions:NSDraggingItemEnumerationConcurrent
                                       forView:nil
                                       classes:[NSArray arrayWithObject:[NSPasteboardItem class]]
                                 searchOptions:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:NSPasteboardURLReadingFileURLsOnlyKey ]
                                    usingBlock:^(NSDraggingItem *draggingItem, NSInteger idx, BOOL *stop)
     {
         [draggingItem setDraggingFrame:NSMakeRect(session.draggingLocation.x-20,
                                                   session.draggingLocation.y-DRAG_IMAGE_HEIGHT+20,
                                                   DRAG_IMAGE_WIDTH,
                                                   DRAG_IMAGE_HEIGHT)
                               contents:image];
     }];
}

你试过NSDraggingFormationNone吗?draggingItem.draggingFrame.origin=mouseLocInView;是的,NSDraggingFormation无效,draggingItem.draggingFrame.origin不是可分配的表达式。这是应用程序的屏幕截图:我的意思是:使用MouseLocalView作为要设置为拖动帧的矩形的原点。我使用NSRect frame=[tableView frameOfCellAtColumn:0行:insertionIndex];raggingItem.draggingFrame=框架;在[info EnumeratingDragingItemsWithOptions:0 forView:tableView类:类搜索选项:nil usingBlock:enumerationBlock]中;我的朋友,谢谢你。经过一年的努力,你给了我我需要的方向。屏幕坐标系通过零。这句话是关键。我在苹果公司开了两张支持票,他们无法给出这个简单的答案。再次感谢你!