2016-06-22 4 views
0

표시된 이미지와 같이 uiimagepicker 컨트롤러에서 선택한 이미지를 어떻게 표시합니까? 나는 collectionview에 검은 영역을 얻고있다. 심지어 가로 uicollectionview를 사용하여 최선의 접근법을 모르겠어요.선택한 사진을 단일 행으로 표시하는 방법 collectionview

Example

+0

귀하의 요구 사항을 이해하지 못했습니다. 정교하게 말씀해 주시겠습니까 –

답변

0

나는 수평 UICollectionView를 사용하여 저렴한 아이디어라고 생각합니다. '그림 단추 추가'를 바닥 글로 추가하면 항상 마지막에 위치하게 만들 수 있습니다.

이렇게하려면 UICollectionViewFlowLayout을 서브 클래 싱하고 layoutAttributesForElementsInRect()를 재정의하십시오.

override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? { 
    if let layoutAttributesForElementsInRect = super.layoutAttributesForElementsInRect(rect), let collectionView = self.collectionView { 

     for layoutAttributes in layoutAttributesForElementsInRect { 
      if layoutAttributes.representedElementKind == UICollectionElementKindSectionFooter { 

       let section = layoutAttributes.indexPath.section 
       let numberOfItemsInSection = collectionView.numberOfItemsInSection(section) 

       if numberOfItemsInSection > 0 { 
        let lastCellIndexPath = NSIndexPath(forItem: max(0, numberOfItemsInSection - 1), inSection: section) 

        if let lastCellAttrs = self.layoutAttributesForItemAtIndexPath(lastCellIndexPath) { 
         var origin = layoutAttributes.frame.origin 

         origin.x = CGRectGetMaxX(lastCellAttrs.frame) 

         layoutAttributes.zIndex = 1024 
         layoutAttributes.frame.origin = origin 
         layoutAttributes.frame.size = layoutAttributes.frame.size 
        } 
       } 
      } 
     } 

     return layoutAttributesForElementsInRect 
    } 

    return nil 
} 
+0

환호하는 친구, 이것이 완벽하게 작동했습니다! –

관련 문제