views:

119

answers:

1

You know that in a lot of Mac/iPhone applications (such as your Finder), when you are dragging a icon around, all other icons will be "repelled away" from your mouse and leave space for the icon you are dragging.

I am wondering if that's a built-in Cocoa function (in layout constraints etc?). If not, is there any library, or documents on how to implement it?

+6  A: 

If you want to get it more-or-less for free, use an NSCollectionView.

If NSCollectionView doesn't fit your needs, it's fairly easy to implement it using NSAnimation. Basically, the way that NSToolbar or NSCollectionView does it (for example), is to figure out where the icon you're dragging would land if you let it go, and it sends the other icons to their new locations using Core Animation to move them smoothly.

NSResponder
yeah but how to calculate where to move each icon? and what happens if in that position, is already another icon?
Victor Jalencas