Why do we need invalidateLayout?

偶尔善良 提交于 2019-12-10 15:27:27

问题


i tried to implement rotation adjustments so in tutorial author was using invalidatelayout function before setting new preferences. but all actually works without invalidateLayout, and yet i tried it in another circumstance before and got the same "nothing" output.

   override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {

    collectionView.collectionViewLayout.invalidateLayout()

    let indexPath = IndexPath(item: pageControl.currentPage, section: 0)
    //scroll to indexPath after the rotation is going
    DispatchQueue.main.async {
        self.collectionView.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true)
        self.collectionView.reloadData()
    }

}

So why do we need invalidateLayout? (and i read docs but it seems that this function is somewhat..it seems do nothing... i don't know...maybe redundant?)

来源:https://stackoverflow.com/questions/49280087/why-do-we-need-invalidatelayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!