Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic "force repel" layout in Cocoa

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?

like image 400
ivanTheTerrible Avatar asked Nov 17 '09 04:11

ivanTheTerrible


1 Answers

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.

like image 84
NSResponder Avatar answered Oct 19 '22 22:10

NSResponder