标签云

微信群

扫码加入我们

WeChat QR Code

I've been banging my head to the wall for about two weeks, I've looked at all the Apple documentation available plus hundreds of websites looking for a hint to solve my problem. I'm implementing:-(void)tableView:(NSTableView *)tableView draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint)screenPoint forRowIndexes:(NSIndexSet *)rowIndexesThe problem that I'm having is that the icon for the dragged files shows up in a different coordinate system and I can't seem to find a way to make the icon show on the screenPoint where the drag began. I've looked into all [tableView convert* ] methods in several combinations without success. Below is the code I'm currently using.-(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:nilusingBlock:^(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; }];}


Have you tried NSDraggingFormationNone ? draggingItem.draggingFrame.origin = mouseLocInView;

2019年04月19日21分26秒

Yes, NSDraggingFormation has no effect anddraggingItem.draggingFrame.origin is not an assignable expression.

2019年04月19日21分26秒

Here is a screenshot of the app: NSTableView

2019年04月19日21分26秒

I meant to say: use mouseLocInView as origin of the rect you are setting as dragging frame.

2019年04月19日21分26秒

I use NSRect frame = [tableView frameOfCellAtColumn:0 row:insertionIndex]; raggingItem.draggingFrame = frame; in [info enumerateDraggingItemsWithOptions:0 forView:tableView classes:classes searchOptions:nil usingBlock:enumerationBlock];

2019年04月20日21分26秒

My friend, I thank you. After a year struggling with this, you have given me the direction I needed. "Pass nil for screen coordinate system." This line was the key. I opened two support tickets with apple and they were unable to give this simple answer. Again, thank you!

2019年04月19日21分26秒