2015-01-26 2 views
1

단일 UICollectionViewCell의 크기를 조정할 수 있는지 궁금합니다. layoutAttributesForItemAtIndexPath & layoutAttributesForElementsInRect와 같은 것들을 보았습니다. 그러나 셀 크기를 조정하면 프레임을 다시 계산해야하므로 각 항목의 프레임을 수동으로 설정해야합니다. 내 계획은 가능할 것입니다. 단일 셀을 선택하고 화면 너비에 맞게 확장하고 다른 모든 셀을 아래로 밀어 넣으면서 다른 셀은 열과 행을 유지합니다.단일 UICollectionViewCell의 크기를 조절할 수 있습니까?

아무도 이것을 얻었습니까?

감사

+0

이이 레이아웃 아니면 그 것이다 내장 플로우 레이아웃? – matt

+0

하위 분류 UICollectionFlowLayout이 시작되었습니다. – bevbomb

+0

글쎄, 그렇게 할 필요는 없습니다. 플로우 레이아웃에는 델리게이트가 있습니다. 원하는 크기로 항목을 만들 수 있습니다. 그냥'sizeForItemAtIndexPath :'를 구현하십시오. – matt

답변

10
var selectedIndexPath: NSIndexPath? 

// MARK: - UICollectionViewDelegate 

override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { 
    selectedIndexPath = indexPath 
    collectionView.performBatchUpdates(nil, completion: nil) 
} 

// MARK: - UICollectionViewDelegateFlowLayout 

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { 
    var size = CGSize(width: 100, height: 100) 

    if selectedIndexPath == indexPath { 
     size.width = CGRectGetWidth(collectionView.frame) 
    } 
    return size 
} 

예, 그것은 간단합니다.

(. 좋은 생각인지 그 질문에 대답하지 않지만 당신은 당신이 그것을 구현할 때 볼)

+0

이것은 훌륭하지만, 더 이상 셀을 선택하지 않아도 크기를 조정할 수있는 방법이 있습니까? 그것들은 즉시 붕괴되고, 팽창하는 힘에 비하면 불쾌합니다. –