In iOS 12, when does the UICollectionView layout cells, use autolayout in nib

后端 未结 7 1654
一整个雨季
一整个雨季 2020-11-28 03:08

Same code like this

collectionLayout.estimatedItemSize = CGSize(width: 50, height: 25)
collectionLayout.itemSize = UICollectionViewFlowLayoutAutomaticSize
co         


        
相关标签:
7条回答
  • 2020-11-28 03:42

    Solution 2 of Cœur's prevents the layout from flashing or updating in front of the user. But it can create problems when you rotate the device. I'm using a variable "shouldInvalidateLayout" in viewWillLayoutSubviews and setting it to false in viewDidAppear.

    private var shouldInvalidateLayout = true
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
    
        shouldInvalidateLayout = false
    }
    
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        if shouldInvalidateLayout {
            collectionView.collectionViewLayout.invalidateLayout()
        }
    }
    
    0 讨论(0)
提交回复
热议问题