2015-01-11 4 views
0

사용자가 누를 때 UICollectionViewCell 크기를 조정하려고 시도했습니다. 현재 셀의 크기는 조정되지만 다른 셀은 조정되지 않습니다. 여기UICollectionView의 크기가 올바르게 조정되지 않음

enter image description here

내가 사용하고있는 코드입니다 : 여기에 문제의 사진입니다. 나는 문제가 무효화 함께 느낌,하지만 나는 확실하지 않다 :

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 


    UICollectionViewCell * cellToChangeSize = [self.collectionView cellForItemAtIndexPath:indexPath]; // Avoid retain cycles 


    void (^animateChangeWidth)() = ^() 
    { 
     CGRect frame = cellToChangeSize.frame; 
     frame.size = CGSizeMake(300, 100); 
     cellToChangeSize.frame = frame; 
    }; 

    // Animate 

    [UIView transitionWithView:cellToChangeSize duration:0.1f options: UIViewAnimationOptionCurveLinear animations:animateChangeWidth completion:^(BOOL finished) { 
     [self.collectionView.collectionViewLayout invalidateLayout]; 


    }]; 

} 

답변

0

당신은 할 수 UICollectionViewDelegateFlowLayout을 확장하고 collectionView을 구현하여 : 레이아웃 : sizeForItemAtIndexPath을 : 방법 : https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UICollectionViewDelegateFlowLayout_protocol/index.html#//apple_ref/occ/intfm/UICollectionViewDelegateFlowLayout/collectionView:layout:sizeForItemAtIndexPath을 :.

collectionview : didSelectItemAtIndexPath :에서 직접 셀을 수정하는 대신 유동 레이아웃 하위 클래스에서 사용할 수 있도록 모델 클래스에서 크기를 설정해야합니다.

희망이 도움이됩니다.

관련 문제