1

ウォーターフォール スタイルのレイアウトを使用してさまざまなサイズのセルを表示する UICollectionView があります。各セルの高さの計算は問題なく機能します。

私が抱えている問題は、各セルの 2 つのアウトレット (UIImage と UILabel) のサイズを変更する必要があり、UICollectionView がフレーム サイズの変更をアニメーション化するのを防ぐためにフレーム サイズを変更する場所がわからないことです。結果なしで、各セルのlayoutSubviewsメソッドとcellForItemAtIndexPathで実行しようとしました。UICollectionView を含むビューコントローラーが表示されるたびに、各セルの 2 つのアウトレットのフレーム変更がアニメーション化されます。

cellForItemAtIndexPath 内の画像だけにフレームを設定する例:

- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView
              cellForItemAtIndexPath:(NSIndexPath *)indexPath {

CVCNewspaper *cell = (CVCNewspaper *)[collectionView dequeueReusableCellWithReuseIdentifier:CELL_IDENTIFIER_NEWSPAPER forIndexPath:indexPath];
BONewspaper *newspaper = [newspapers objectAtIndex:indexPath.row];
CGFloat width = cell.frame.size.width;

// Calculate rect for imageView
CGFloat objectWidth = newspaper.coverNews.imageWidth ? newspaper.coverNews.imageWidth : 180;
CGFloat objectHeight = newspaper.coverNews.imageHeight ? newspaper.coverNews.imageHeight : 100;
CGFloat scaledHeight = floorf(objectHeight / (objectWidth / width));

cell.imageViewCover.frame = CGRectMake(MARGINVIEW, HEADERHEIGHT + 5, width, scaledHeight);

[cell fillCellWithNewspaper:newspaper];

return cell;

}

4

0 に答える 0