UICollectionViewCellのItemSizeを動的に変えた場合(デバイスを回転させたときにItemSizeを変更した)にUICollectionViewCellのAutoLayoutが効かなくなる。という現象に遭遇しました。(そもそもItemSizeを途中で変えるというアプローチがダメな気がしますが・・・。)
とりあえず、解決策としては - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPathでUICollectionViewCellが持っているcontentViewに対してAutoLayoutの設定を書いてやれば解決しました。
contentViewにAutoLayout設定
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
//Masonryを使っているのでAutoLayoutは以下のような記述
[cell.contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(cell);
}];
//do something
return cell;
}