0

I am looking for a way how to constrain the NSDraggingItem position during dragging. I first checked if the enumerateDraggingItemsWithOptions: method could help. I tried to set the draggingFrame of each enumerated item to (my) snap position. It doesn't work. The documentation says that: The dragging frame provides the spatial relationship between NSDraggingItem instances when the dragging formation is set to NSDraggingFormationNone, and it seems like there is no way how to do it. Actually, any changes to the draggingFrame change the position of the dragging item(s). I call the enumerateDraggingItemsWithOptions: from - (NSDragOperation)draggingUpdated: (id)sender. Thank you for any hint.

[sender enumerateDraggingItemsWithOptions: NSDraggingItemEnumerationConcurrent
                                              forView: self
                                              classes: @[NSPasteboardItem.class]
                                        searchOptions: @{NSPasteboardURLReadingFileURLsOnlyKey: @(NO)}
                                           usingBlock: ^(NSDraggingItem * _Nonnull draggingItem, NSInteger idx, BOOL * _Nonnull stop) {
            
            
            NSRect newFrame = NSMakeRect(snapOrigin.x, snapOrigin, draggingItem.draggingFrame.size.width, draggingItem.draggingFrame.size.height);
                draggingItem.draggingFrame = newFrame;
        }];
Jared
  • 130
  • 1
  • 7
  • have you tried [draggingUpdated:](https://developer.apple.com/documentation/appkit/nsdraggingdestination/1415998-draggingupdated?language=objc)? "Invoked periodically as the image is held within the destination area, allowing modification of the dragging operation or mouse-pointer position." – Willeke Jul 25 '22 at 14:00
  • Yes, I am calling enumerateDraggingItemsWithOptions: in - (NSDragOperation)draggingUpdated: (id)sender. I checked the coordinates of NSRect passing to draggingItem.draggingFrame. It is valid. If I take draggingItem.draggingFrame and move its origin (10px), the resulting position of the draggingItem doesn't seem to be changed. – Jared Jul 25 '22 at 21:50

0 Answers0