BalestraPatrick
BalestraPatrick

Reputation: 10144

UICollectionView custom FlowLayout where to specify

I want to add a UIKitDynamics effect to my collectionView (which is not managed by a normal UIViewController). I am using Storyboard.

I am using this tutorial but I am not able to integrate the code with my project: http://www.objc.io/issue-5/collection-views-and-uidynamics.html

I have created the CollectionViewFlowLayout subclass but then I don't know where to set it as custom subclass. I tried in my storyboard file but it doesn't work.

In the tutorial there is also this line that refers to this code:

-(void)viewDidAppear:(BOOL)animated 
{
     [super viewDidAppear:animated];
     [self.collectionViewLayout invalidateLayout];
} 

Notice that it’s invalidating the layout when the view first appears. That’s a consequence of not using Storyboards (the timing of the first invocation of the prepareLayout method is different when using Storyboards – or not – something they didn’t tell you in the WWDC video).

This sentence is not clear to me. What do I need to do if I am using storyboard?

Thanks!

Upvotes: 1

Views: 1900

Answers (2)

Arsalan
Arsalan

Reputation: 170

Override init(coder aDecoder: NSCoder) and it should solve the problem.

Upvotes: 0

jhilgert00
jhilgert00

Reputation: 5489

If you select your UICollectionView in your Storyboard, you should be able to change the layout to "Custom" then choose your subclass from the list.

enter image description here

Upvotes: 4

Related Questions