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

后端 未结 7 1677
一整个雨季
一整个雨季 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:21

    Try this

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
    
        DispatchQueue.main.async {
            self.collectionView.collectionViewLayout.invalidateLayout()
        }
    }
    

    Adding to viewDidAppear and viewWillAppear will of course work. But viewDidAppear will cause a glitch gor the user.

提交回复
热议问题