CollectionView 宽度在 Xamarin forms iOS Portrait/Landscape 模式下不正确

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

我有一个 Xamarin 应用程序,我正在使用集合视图来显示项目。 项目的宽度第一次是正确的,然后切换回横向模式,然后切换回纵向模式,项目列表的宽度采用以前的横向模式宽度。 我也收到异常

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

我已经使用 ItemTemplate 和页眉布局创建了 CustomCollectionView,但是由于页眉布局,页眉是正确的,但是当项目选择项目模板时宽度不正确(它采用横向模式的宽度纵向模式)。 切换 landscape/portrait 模式时出现上述错误,请同时查找图片参考)

任何人都可以帮助我将 CollectionView 的宽度设置为合适的宽度吗?

我没有使用过 Xamarin,但我在 Xcode 中也遇到过同样的问题。问题是在我们设置 flowLayout.estimatedItemSize = .automatic 时引起的,而不是尝试给它一个大小,例如 flowLayout.estimatedItemSize = CGSize(width: 1, height: 1)

注意: 类似的答案请查看

你的 Xamarin.Fomrs 版本是多少?

如果不是最新版本,更新到5.0.0.2012试试,已经修复

你可以看看https://github.com/xamarin/Xamarin.Forms/issues/13538

我认为是 Xamarin.Fomrs 版本的问题,因为我也遇到了类似的问题。

请更新版本为5.0.0.2012