简体   繁体   English

UICollectionView无法折叠或删除补充视图

[英]UICollectionView can't collapse or remove supplementary view

I have a uicollectionview using flow layout that has a supplementary header view which is a view that I only sometimes want to display. 我有一个使用流布局的uicollectionview,它有一个补充的标题视图,这是我有时只想显示的视图。 So basically I want to have a button that will, when clicked, remove the supplementary view from the collection view and also re-place all the items in the collection view with the consideration that the header is gone. 所以基本上我想要一个按钮,当点击它时,将从集合视图中删除补充视图,并重新放置集合视图中的所有项目,同时考虑标题已消失。 Is this possible? 这可能吗? I've tried it repeatedly in many ways. 我在很多方面都反复尝试过。 Changing the reference header size, changing my answer to the delegate method for the header size, invalidating the layout, reloading the data etc etc etc. What am I missing? 更改引用标头大小,更改我对标题大小的委托方法的答案,使布局无效,重新加载数据等等。我缺少什么?

I just ran a test. 我刚刚参加了测试。 I think that it's related to using UIDynamics, what is it in UIDynamics that would override my delegate response for header section reference size? 我认为它与使用UIDynamics有关,UIDynamics中的什么会覆盖我的头部分参考大小的委托响应?

In your delegate's layout methods return the appropriate size for whatever state you're interested in: 在您的委托的布局方法中,为您感兴趣的任何州返回适当的大小:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    if (self.headerVisble) {
        return CGSizeMake(collectionView.bounds.size.width, 30.0f);
    }
    else {
        return CGSizeZero;
    }
}

Then when you need to update the layout call: 然后,当您需要更新布局调用时:

[collectionView.collectionViewLayout invalidateLayout];

The collection view will ask the Layout object for new info which will in turn ask your delegate. 集合视图将向Layout对象询问新信息,然后再询问您的代理人。 I believe it will animate the change too. 我相信它也会改变这种变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM