我试图通过在加载视图控制器时将其设置为 0 来调整 UICollectionView 高度的大小,然后在按下按钮时通过动画增加其大小。我尝试了一些不同的东西,但它的大小根本没有改变。以下是我尝试将其高度更改为 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 方法更改高度。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)