Dynamically change NSCollectionView items based on view width
Dynamically change NSCollectionView items based on view width
- Subject: Dynamically change NSCollectionView items based on view width
- From: Demitri Muna <email@hidden>
- Date: Sat, 06 Apr 2019 17:46:23 -0400
Hello,
I have a 10.11+ NSCollectionView. I have two representations (subclasses of
NSCollectionViewItem) of the data - one large and one small. When the view is
resized to be narrower than the large representation, I’d like to swap the
views to the smaller versions. Similarly, when the window is widened enough to
accommodate at least a single of the larger views, I’d like the views to change
again. I’ve not been able to make this work.
I have set up an NSViewBoundsDidChangeNotification so I know when the width of
the view crosses the threshold. I’ve tried:
- [collectionView reloadData]
- [collectionView.collectionViewLayout invalidateLayout] (on the
NSCollectionViewFlowLayout)
I think I just want to invalidate all of the already created views and get the
collection view to call makeItemWithIdentifier:forIndexPath: again.
One option I haven’t explored is to handle the change within a single
NSCollectionViewItem subclass (two views in the one .xib), but since the
representations are sufficiently different (e.g different number of subviews)
I’m worried about running into auto layout issues during the transition. Also
it feels messier.
Bonus points for how to accomplish this with animation!
Thanks,
Demitri
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden