I am programmatically creating a UICollectionView
in viewDidLoad
and then setting auto layout constraints on it. I need to know exactly what the collection view's width will be after it is displayed to the user, but I need that information in viewDidLoad
(cannot use willLayoutSubviews
etc).
How do you force layout to occur so I can guarantee the width will update to be the real width in viewDidLoad
?
//viewDidLoad:
let collectionView = //...
self.view.addSubview(collectionView)
//add constraints here
let wid = collectionView.frame.size.width //0
//viewDidAppear:
let wid = collectionView.frame.size.width //603
I have tried calling self.view.layoutSubviews()
but this didn't resolve the issue entirely. It changed wid
to 720 instead of 0, but that's not correct.
I am attempting this in a Today extension, which may differ from a traditional view controller.