【发布时间】:2020-12-26 00:47:58
【问题描述】:
我想单击按钮然后显示警报视图。此警报视图将接收两个数组。
警报视图将通过两个 UICollectionView 布局大小自行刷新。
[self.topCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:self.topSelectIndex inSection:0] animated:false scrollPosition:UICollectionViewScrollPositionBottom];
[self.bottomCollectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:self.bottomSelectIndex inSection:0] animated:false scrollPosition:UICollectionViewScrollPositionBottom];
[self layoutIfNeeded];
CGFloat topFloatHeight = self.topCollectionView.collectionViewLayout.collectionViewContentSize.height;
CGFloat bottomFloatHeight = self.bottomCollectionView.collectionViewLayout.collectionViewContentSize.height;
self.topCollectionHeightConstrait.constant = topFloatHeight;
self.bottomCollectionHeightConstraint.constant = bottomFloatHeight;
// CGFloat bigScrollViewHeight = self.bigScrollView.contentLayoutGuide.heightAnchor
CGFloat catHeight = topFloatHeight + bottomFloatHeight + 200;
CGFloat screenHeight = kScreenHeight - 180;
if( catHeight < screenHeight) {
self.scrollBoxHeightCont.constant = catHeight;
}else {
self.scrollBoxHeightCont.constant = screenHeight;
}
self.bigScrollView.contentSize = CGSizeMake(0, catHeight);
[self.topCollectionView reloadData];
[self.bottomCollectionView reloadData];
如您所见,关键代码是
self.bigScrollView.contentSize = CGSizeMake(0, catHeight);
代码改变了 bigScrollview 的 contentSize,alert view 下次总是显示上面代码内容中计算的正确大小,而不是这次。
为什么不直接显示大小合适的内容? 是否有其他解决方案可以获得相同的结果?
【问题讨论】:
标签: ios uicollectionview uiscrollview