F
F
FlooDwm2016-11-17 12:17:42
iOS
FlooDwm, 2016-11-17 12:17:42

Why is the size of the items in the collectionview displayed incorrectly when I change from portrait to landscape view?

There is a tabBar that is made in the form of a collectionview with 4 items, the size of the items is determined by:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize(width: frame.width/4, height: frame. height) }
But when I set the view they change in size i.e. as far as I understand, the size is not recalculated How to fix it
bcf4917c67ef4fb696ded2d040949a02.png3407bd8a9859467e94d173e9373011c3.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FlooDwm, 2016-11-17
@FlooDwm

override func viewWillLayoutSubviews() {
tabBar.collectionTab.collectionViewLayout.invalidateLayout()
}
This thing helped

B
briahas, 2016-11-17
@briahas

Probably the frame variable has not updated its data. What does the debugger say?
---
how to check? - put a breakpoint on the line return CGSize(width: frame.width/4, height: frame.height) ; when it stops - look in the list of variables what is the value of the variable
how to update? Is there a screen rotation tracking method? Let me look for you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question