the behavior of the UICollectionViewFlowLayout is not defined, because the cell width is greater than collectionView width

后端 未结 20 2173
温柔的废话
温柔的废话 2020-12-01 01:53

2015-08-18 16:07:51.523 Example[16070:269647] the behavior of the UICollectionViewFlowLayout is not defined because: 2015-08-18 16:07:51.523
Example

20条回答
  •  执笔经年
    2020-12-01 02:26

    I've been struggling with this problem for some hours, too.

    My UICollectionViewController is embedded in a container view, when rotating the iPad from landscape to portrait it showed the error. The cells did resize though.

    I solved the error by calling the following in the UICollectionViewController:

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        self.collectionView.collectionViewLayout.invalidateLayout()
    
        super.viewWillTransition(to: size, with: coordinator)
    }
    

    The "super" has to be called after invalidating the layout.

    Additionally I needed to call the following in the view where the container view is embedded in:

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
    
        DispatchQueue.main.async {
            self.collectionViewController.collectionView.reloadData()
        }
    }
    

    This way, the cells are updated after the screen rotation is done.

提交回复
热议问题