UICollectionView无法折叠或删除补充视图 [英] UICollectionView can't collapse or remove supplementary view

查看:119
本文介绍了UICollectionView无法折叠或删除补充视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用流布局的uicollectionview,它有一个补充的标题视图,这是我有时只想显示的视图。所以基本上我想要一个按钮,当点击它时,从集合视图中删除补充视图,并重新放置集合视图中的所有项目,同时考虑标题已消失。这可能吗?我在很多方面都反复尝试过。更改参考标题大小,更改我对标题大小的委托方法的答案,使布局无效,重新加载数据等等。我缺少什么?

I have a uicollectionview using flow layout that has a supplementary header view which is a view that I only sometimes want to display. 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刚刚进行了测试。我认为它与使用UIDynamics有关,UIDynamics中的什么会覆盖我的头部分引用大小的委托响应?

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?

推荐答案

在你的委托的布局方法中,为你感兴趣的任何州返回适当的大小:

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];

集合视图将向Layout对象询问新信息,然后再询问您的代理人。我相信它也会改变这种变化。

The collection view will ask the Layout object for new info which will in turn ask your delegate. I believe it will animate the change too.

这篇关于UICollectionView无法折叠或删除补充视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆