2015-11-26 111 views
0

我在故事板的單元格中有一個UICollectionViewCell。前6個單元的單元大小爲45,最後一個單元的單元大小爲50。UICollectionView單元格大小ContentView問題

故事板單元尺寸具有寬度=上iPhone模擬器4S運行時,會發生60.

以下問題。

enter image description here

如果你看到在位置2,4,6細胞有UICollectionView的紅色背景。

我得到以下layoutSubView的子類。

Frame = {{0, 0}, {50, 60}} 
Frame = {{0, 0}, {45, 60}} 
Frame = {{0, 0}, {45, 60}} 
Frame = {{0, 0}, {45, 60}} 
Frame = {{0, 0}, {45, 60}} 
Frame = {{0, 0}, {45, 60}} 
Frame = {{0, 0}, {45, 60}} 


- (void)layoutSubviews 
{ 
    [super layoutSubviews]; 

    NSLog(@"Frame = %@",NSStringFromCGRect(self.bounds)); 
    self.contentView.frame = self.bounds; 
} 

此外,在awakefromnib中添加了調整大小,這沒有奏效。

-(void)awakeFromNib{ 
    [super awakeFromNib]; 

    self.contentView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth ; 
} 

以上印出的結果是正確的,尺寸是完美的。

添加在視圖控制器下面也沒有在url.

工作

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{ 
    return 0.0; 
} 
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{ 
    return 0.0; 
} 

演示項目是有一段時間在進一步的調查,我發現是因爲縮放模擬器。屏幕與4s模擬器。我不知道是否在設備上會導致任何問題。

100%=>導致確定 75%=>紅色背景線條出現 50%=>導致確定 33%=>導致確定 25%=>紅色背景線條出現

enter image description hereenter image description hereenter image description here enter image description hereenter image description here

+0

你能否提供更多關於你的佈局的信息,並且是你的'celloectionViewCells'的大小不同?如果是這樣,那麼你可能需要爲你的collectionView而不是flowLayout使用自定義佈局。 – Adeel

回答

0

嘗試設置的CollectionView的約束這樣 enter image description here

+0

你有沒有解決這個問題? –