UICollectionView always auto sizing cells. Not using sizes returned from delegate

若如初见. 提交于 2019-12-08 19:31:55

问题


Recently upgraded to Xcode 11 / iOS13. Working on a new view controller. The UICollectionView is calling my sizeForItemAtPath delegate method, but it seems like the collection view is always choosing self sizing based on constraints. But I don't want it to!

I tried setting the estimatedSize to 1x1 just to try and work around this. Didn't work. I've breakpointed on all the delegate / datasource methods and don't see anything out of the ordinary.

I also came across this (`systemLayoutSizeFittingSize` not called on iOS 13), maybe my issue is related? I am able to fix the issue by overriding the systemFittingSize method in that link - but I really shouldn't have to.

The odd thing I find is that any existing xibs with collection views are working as expected - the only difference seems to be me creating the cell / collection view with Xcode 11 VS Xcode 10.

I also noticed that UICollectionViewCell elements in Xcode11 contain a "Content View" - but Xcode 10 xibs don't have a Content View.

Anyone else experience this?


回答1:


There's a setting in interface builder for estimated size - set it to None.

Change to None:




回答2:


I actually have never worked with XIBs or flow layouts, but I am currently working on some custom collection views: from what I know, in the most general case, it's not the collection view itself who's "choosing self-sizing", it's the layout object.

Collection view on itself or it's delegate do not have any methods that ask cells for their preferred sizes. On the other hand, the flow layout does. It is known that flow layout checks internally if a cell uses auto layout, and, if the cell does, it ignores the information supplied by the delegate.

One can opt out of that behavior by subclassing the layout and returning false in shouldInvalidateLayout(forPreferredLayoutAttributes:, withOriginalAttributes:).



来源:https://stackoverflow.com/questions/58262024/uicollectionview-always-auto-sizing-cells-not-using-sizes-returned-from-delegat

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