이 작업을 수행하는 방법을 보여주기 위해의 "Resize"샘플 프로젝트를 업데이트했습니다.
이 접근법은 TLLayoutTransitioning 콜백 중 하나를 사용하여 전환의 모든 단계에서 글꼴 크기를 업데이트하는 것을 포함합니다. 큰 크기로 흐리게 스케일 된 텍스트를 얻으므로 아핀 변환을 사용하지 않을 것입니다.
첫 번째 단계는 레이블의 글꼴 크기를 설정하는 방법을 정의하는 것입니다. 당신은 당신이 원하는 수식을 사용할 수 있지만 비례 셀의 폭 글꼴 스케일을했습니다 : 적절하게 조정됩니다
- (void)updateLabelScale:(UILabel *)label cellSize:(CGSize)cellSize
{
CGFloat pointSize = cellSize.width * 17/128.f;
label.font = [UIFont fontWithName:label.font.fontName size:pointSize];
}
당신은 화면에 표시하는 새로운 라벨을 보장하기 위해 cellForItemAtIndexPath
에서이 메소드를 호출 할 수 있습니다 :
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [super collectionView:collectionView cellForItemAtIndexPath:indexPath];
UILabel *label = (UILabel *)[cell viewWithTag:1];
...
[self updateLabelScale:label cellSize:cell.bounds.size];
return cell;
}
레이블의 중심은 셀의 중심에 구속되고, 크기는 intrinsicContentSize
에 의해 결정된다. 따라서 글꼴을 변경하면 레이블의 크기가 자동으로 조정됩니다.
마지막으로 updateLayoutAttributes
콜백을 사용하여 새 레이아웃 속성을 기반으로 표시되는 셀의 글꼴 크기를 업데이트합니다 (보이지 않는 셀은 걱정할 필요가 없습니다. cellForRowAtIndexPath
) :
__weak ResizeCollectionViewController *weakSelf = self;
[layout setUpdateLayoutAttributes:^UICollectionViewLayoutAttributes *(UICollectionViewLayoutAttributes *pose, UICollectionViewLayoutAttributes *fromPose, UICollectionViewLayoutAttributes *toPose, CGFloat progress) {
CGSize cellSize = pose.bounds.size;
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:pose.indexPath];
if (cell) {
UILabel *label = (UILabel *)[cell viewWithTag:1];
[weakSelf updateLabelScale:label cellSize:cellSize];
}
return nil;
}];
죄송합니다. 나는 GitGHub에 답변과 샘플 코드를 게시했다. –