我正在使用 https://github.com/jamztang/CSStickyHeaderFlowLayout 中的 CSStickyHeaderFlowLayout|
作为我的应用程序的一部分,我在标题 View /单元格中有一个按钮,该按钮发送到它需要增长的 Collection View 。反过来, Collection View 更改 CSStickyHeaderFlowLayout 中的标题首选大小,并将 invalidateLayout 发送到 CSStickyHeaderFlowLayout。尝试通过动画 block 制作动画效果不佳,因为它会将标题从按钮移动到顶部。这真的很奇怪。有没有办法让 flowLayout 正确地为补充 View 中的变化设置动画?
这是我更改大小的代码。
- (void)treckDetailMapCellSizeToggle:(BOOL)toggle {
//Modifier l'attribu de la map et invalider le layout pour le redessiner.
CSStickyHeaderFlowLayout *layout = (id)self.collectionViewLayout;
if ([layout isKindOfClass:[CSStickyHeaderFlowLayout class]]) {
[UIView animateWithDuration:0.5 animations: ^{
if (isMapCellExpended) {
isMapCellExpended = NO;
layout.parallaxHeaderReferenceSize = CGSizeMake(self.view.frame.size.width, HEADER_VIEW_PREFERED_SIZE);
}
else {
isMapCellExpended = YES;
layout.parallaxHeaderReferenceSize = CGSizeMake(self.view.frame.size.width, HEADER_VIEW_MAX_SIZE);
}
[layout invalidateLayout];
}];
}
}
这是一段视频,讲述了当我点击名为“Ajouter a la carte”的按钮时发生的事情。
https://www.youtube.com/watch?v=aqm99HebvwE
编辑:
感谢阅读此页面(我以前从未见过)。我发现这会使它好一点但不能解决问题。 :
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
CSStickyHeaderFlowLayout *layout = (id)self.collectionViewLayout;
if ([layout isKindOfClass:[CSStickyHeaderFlowLayout class]]) {
[self.collectionView performBatchUpdates: ^{
preferedSize = preferedSize == 200 ? 300 : 200;
layout.parallaxHeaderReferenceSize = CGSizeMake(self.view.frame.size.width, preferedSize);
} completion: ^(BOOL finished) {
}];
}
}
最佳答案
要为大小更改设置动画,请在 View 动画闭包中使布局无效。尺寸本身应该通过适当的布局委托(delegate)方法设置,例如collectionView(collectionView:collectionViewLayout:referenceSizeForHeaderInSection:)
UIView.animate(withDuration: 0.33) {
self.collectionView.collectionViewLayout.invalidateLayout()
}
关于ios - 动画 UICollectionView 补充 View 调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29567045/