Search code examples
iosxamarin.formsxamarin.iosuicollectionviewcollectionview

CollectionView width is not correct in Xamarin forms iOS Portrait/Landscape mode


I have a Xamarin app and I am using a collection view for displaying items. The Width of items are correct for the first time then switch back to Landscape mode then switch back to portrait mode and the width of items list taking the previous landscape mode width. I am also receiving the exception as

The behavior of the UICollectionViewFlowLayout is not defined because: the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values. Please check the values returned by the delegate. The relevant UICollectionViewFlowLayout instance is <Xamarin_Forms_Platform_iOS_ListViewLayout: 0x7fd42ca25d10>, and it is attached to <UICollectionView: 0x7fd42ab11000; frame = (0 0; 635.5 1136); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x6000029307e0>; layer = <CALayer: 0x600006f5d820>; contentOffset: {0, -51}; contentSize: {635.5, 0}; adjustedContentInset: {51, 0, 0, 0}; layout: <Xamarin_Forms_Platform_iOS_ListViewLayout: 0x7fd42ca25d10>; dataSource: <Xamarin_Forms_Platform_iOS_GroupableItemsViewController_1: 0x7fd42a450280>>. Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

Landscape mode

Portrait mode

I have created CustomCollectionView with ItemTemplate and Header layout, but the header is coming correct due to the header layout, but when items are selecting item template then width are not taking correct(It is taking the width of the landscape mode in portrait mode). When switching the landscape/portrait mode I am receiving the above error and please find the image reference as well)

Can anyone help me with setting the width of the CollectionView with the proper width?


Solution

  • I think the issue is with the Xamarin.Fomrs version, because I was also faced the similar issue.

    Please update the version to 5.0.0.2012