2017-04-10 5 views
0

나는이 하나의 같은 콜렉션 뷰 구축하려는 : 중앙에 더 큰 셀을 가지고 있으며, 세포가 컨테이너보기의 중심에 물리 Collection View아이폰 OS 스위프트 3 : UICollectionView 수평 가운데 더 큰 세포

을하지만, 스위프트와 3. 이처럼 사용자 정의 Collection View를 작성하는 방법을 배우고 싶기 때문에 라이브러리를 사용하고 싶지 않습니다.

나는

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 
     return CGSize(width: collectionView.frame.size.width, height: collectionView.frame.size.height) 
    } 

메이크업 컬렉션보기 기능 SO하지만 적절한 해결책을 찾을 아직

+2

안녕하세요, 링크를 확인하고 도움이된다면 투표. https://github.com/ink-spot/UPCarouselFlowLayout –

+0

훌륭한 작품입니다. 어떻게 대답 할 수 있습니까? –

+0

위의 버튼을 눌러 투표하십시오. 포인터를 내 대답으로 가져 가면 두 가지를 모두 찾을 수 있습니다. 감사. –

답변

0

쓰기 수평 [스크롤 방향]

및 진드기 스크롤 가능 [스크롤]을 통해 검색 한 및 페이징 인 에이블

셀을 크게 만들기

+0

센터 셀을 왼쪽 및 오른쪽 셀보다 크게 만드는 방법은 무엇입니까? –

0

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { 

    let offSet = self.collectionView.contentOffset 
    let width = self.collectionView.bounds.size.width 

    let index = round(offSet.x/width) 
    let newPoint = CGPoint(x: index * size.width, y: offSet.y) 


    coordinator.animate(alongsideTransition: { (UIViewControllerTransitionCoordinatorContext) in 

    },completion: {(UIVIewTransitionCoordinatorContext) in 
     self.collectionView.reloadData() 
     self.collectionView.setContentOffset(newPoint, animated: true) 
    }) 

} 
UICollectionViewFlowLayout를 서브 클래스 화해 오버라이드 (override) 할 필요가이를 달성하려면 : 변경된 속성을

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath 

을 다음 super.layoutAt 전화 ... 그리고 그것의 .transform의 속성을 통해 반환 셀을 변경하고 반환

다음은 이전에 작성한 예입니다.

override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { 

var att = super.layoutAttributesForElements(in: rect)! 

if !(delegate?.reelPlayerFlowIsPreviewMode() ?? true) { 
    return att 
} 
let region = CGRect(x: (self.collectionView?.contentOffset.x)!, 
        y: (self.collectionView?.contentOffset.y)!, 
        width: (self.collectionView?.bounds.size.width)!, 
        height: (self.collectionView?.bounds.size.height)!) 

let center = CGPoint(x: region.midX, y: region.midY) 

for theCell in att { 

    print("\(theCell.indexPath.item)\n\(theCell)\n") 
    let cell = theCell.copy() as! UICollectionViewLayoutAttributes 
    var f = cell.frame 
    let cellCenter = CGPoint(x: f.midX, y: f.midY) 
    let realDistance = min(center.x - cellCenter.x, region.width) 
    let distance = abs(realDistance) 
    let d = (region.width - distance)/region.width 
    let p = (max(d, ReelPlayerFlowLayout.minPercent) * ReelPlayerFlowLayout.maxPercent) 

    f.origin.x += (realDistance * ((1 - ReelPlayerFlowLayout.maxPercent) + (ReelPlayerFlowLayout.maxPercent - ReelPlayerFlowLayout.minPercent))) 

    cell.frame = f 
    cell.size = CGSize (width: f.width * p, height: f.height * p)    
    let index = att.index(of: theCell)! 
    att[index] = cell 
} 

return att 

}