János János - 3 months ago 15
iOS Question

20px gap between collection view and its container

I can see a 20px gap between collection view and its container and I do not know why. I set all constraints to stretch view the full container. Any idea?

enter image description here

Answer

For UICollectionViewController it is important to set view's frame after transition. In somehow UITableViewController set itself automatically.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        let src = segue.sourceViewController as UIViewController
        let dst = segue.destinationViewController as UIViewController

        addChildViewController(dst)
        view.addSubview(dst.view)
        dst.didMoveToParentViewController(self)
        dst.view.frame = self.view.bounds //<-- this line is important for collection view
    }