调整 UICollectionView 高度 [英] Resize UICollectionView Height

查看:115
本文介绍了调整 UICollectionView 高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过在加载视图控制器时将其设置为 0 来调整 UICollectionView 高度的大小,然后在按下按钮时通过动画增加其大小.我尝试了一些不同的东西,但它的大小根本没有改变.这是我尝试将其高度更改为 0 的所有不同内容:

I'm trying to resize a UICollectionView height by setting it to 0 when the view controller is loaded, then increasing its size with an animation when a button is pressed. I've tried a few different things but it doesn't change in size at all. Here's all the different things I've tried to change its height to 0:

CGRect bounds = [self.collectionView bounds];
[self.collectionView setBounds:CGRectMake(bounds.origin.x,
                                          bounds.origin.y,
                                          bounds.size.width,
                                          bounds.size.height - 100)];

....

CGRect frame = [self.collectionView frame];
[self.collectionView setFrame:CGRectMake(frame.origin.x,
                               frame.origin.y,
                               frame.size.width,
                               frame.size.height - 100)];

....

CGRect frame = self.collectionView.frame;
frame.size.height -= 100;
self.collectionView.frame = frame;

....

 self.collectionView.clipsToBounds = YES;
 self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleHeight;

推荐答案

如果您使用 Interface Builder 进行 UICollectionView 初始化,请从创建 CollectionView 的 xib 文件中的文件检查器中关闭使用自动布局".然后您可以使用 setFrame 或 setBounds 方法更改高度.

If you are using Interface Builder for UICollectionView initialisation, switch off "Use Autolayout" from the File Inspector in the xib file where the your CollectionView is created. Then you can change the height with setFrame or setBounds methods.

这篇关于调整 UICollectionView 高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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