Nested UICollectionViews, AutoLayout and rotation in iOS 8

后端 未结 7 962
青春惊慌失措
青春惊慌失措 2021-02-03 16:20

I started to use AutoLayout for a large project and was positively surprised about it. However, now I have to adjust the project to accommodate for rotation and size classes, an

相关标签:
7条回答
  • 2021-02-03 16:46

    This has been an ongoing issue in our app but finally I achieved what I believe to be the best and easiest solution so far. Basically you'll need to remove the parent (base) collection view from the superview when device rotates and then add it again to the superview. If you do it properly the system will even animate it for you! Here's an example:

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator);
    
        self.collectionView.removeFromSuperview();
        self.collectionView = self.getAFreshCollectionViewInstance();
        self.setupCollectionViewFrameUsingAutoLayout();
    }
    

    As for the data of the collection view, it works just fine by using the existing data source and this is really efficient when data is loaded from the web.

    0 讨论(0)
提交回复
热议问题