2016-02-05 70 views
0

我有以下设置,其中位于两个标题之间的UICollectionView调整大小以适应其所有单元格。它基本上是表格格式的2x2布局。现在如何调整调整UICollectionView大小的Autolayout位置?

enter image description here

一旦数据被加载我使用以下方法来调整UICollectionView

- (void)loadContent { 

[self.collectionViewAboutProperty reloadData]; 

[self.labelAddress setText:stringAddress]; 

float totRows = [self.dictAboutProperty count]; 

float cHeight = ceil(totRows/2.0); 

float collectionHeight = (cHeight * 20) + (cHeight * 5); 

[self.collectionViewAboutProperty setFrame:CGRectMake(self.collectionViewAboutProperty.frame.origin.x, self.collectionViewAboutProperty.frame.origin.y, self.collectionViewAboutProperty.frame.size.width, collectionHeight)]; 

} 

问题是,当上述情况发生时,它会覆盖底部标题。这几乎就好像底部标题上的Autolayout约束完全被忽略了一样。在那一刻我把它设置为从上面的大约25像素的空间UICollectionView

我该如何使内容被加载和集合视图被大小调整后,下面的视图更新自己以满足约束?

感谢

+0

创建自定义布局是一个好得多的想法,但是如果您尝试将整个代码片段放入“UICollectionView”自定义子集的'-layoutSubviews'方法中,那么这对您来说可能是一个合理的轻量级解决方案 - 但我会选择自定义布局,更加优雅,并且它专门用于处理这种场景。 – holex

+0

[self.labelAddress setText:stringAddress]; float totRows = [self.dictAboutProperty count]; float cHeight = ceil(totRows/2.0); float collectionHeight =(cHeight * 20)+(cHeight * 5); [self.collectionViewAboutProperty SETFRAME:CGRectMake(self.collectionViewAboutProperty.frame.origin.x,self.collectionViewAboutProperty.frame.origin.y,self.collectionViewAboutProperty.frame.size.width,collectionHeight)]; – Rafeek

回答

1
[self.labelAddress setText:stringAddress]; 

float totRows = [self.dictAboutProperty count]; 

    float cHeight = ceil(totRows/2.0); 

    float collectionHeight = (cHeight * 20) + (cHeight * 5); 

    [self.collectionViewAboutProperty setFrame:CGRectMake(self.collectionViewAboutProperty.frame.origin.x, self.collectionViewAboutProperty.frame.origin.y, self.collectionViewAboutProperty.frame.size.width, collectionHeight)]; 
    [self.collectionViewAboutProperty reloadData]; 

将解决您的问题。