Jared
Jared

Reputation: 180

Snapping (constraining drag item's position) during NSDraggingSession

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;
        }];

Upvotes: 0

Views: 83

Answers (0)

Related Questions