using Xcode 7.0 beta, Swift 2.0, IOS 9 supported
I have a View Controller, which contains a Collection View. Inside is a header: Collection Reusable View, a collection: Collection View Cell and a footer: Collection Reusable View.
Inside the header, I have the functionality to login, register or logout. Depending on what button is clicked, Views inside this header will be hidden or not. Now the last thing I have to do is re-size the frame height of the header view (Collection Reusable View). Because when logged in, both RegisterView and LoginView will be hidden which will leave a large amount of empty space.
here is an image of my structure:
I quickly noticed that I'm unable to add any constraints to the Collection Reusable View :(
All the functionality for the header Collection Reusable View is inside a class that extends UICollectionReusableView
. I'm able to read self.frame.height
, but I cannot write to it. I seem to be able to edit the frame (why is height read-only, while frame is not, apple?). This however has no effect, even self.frame = CGRectZero
doesn't do anything.
I noticed I can do this inside the main ViewController.swift, when initializing the header and footer (func collectionView, switch on kind -> UICollectionElementKindSectionHeader
), but this is not what I want as it should change on button click.
For now, I move the RegisterView up (I edit the top constraint in the code).