임의의 위치에서collectionView 관성 스크롤 중지

5143 단어 Swift

targetContentOffset 사용



여기를 참고했어요.이게 수직으로 굴러갈 때
PVSCellPagedTableView
UITableView+CellPaging.swift
나는 이 가로판을 만들어 보았다.
func pvs_cellPagingScrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>, cellWidth: CGFloat, contentInsetX: CGFloat = 0) {

    var targetContentOffsetCorrected: CGPoint = targetContentOffset.memory
    targetContentOffsetCorrected.x += contentInsetX


    let targetCellIndexPath = self.collectionView?.indexPathForItemAtPoint(targetContentOffsetCorrected)

    let targetCellRect = self.collectionView?.cellForItemAtIndexPath(targetCellIndexPath!)

    var targetCellXCenter = targetCellRect?.frame.origin.x
    println(targetCellXCenter)

    let isJumpingDown = (targetContentOffsetCorrected.x % cellWidth) > (cellWidth / 2)

    if isJumpingDown == true {
        let nextPlace = Int(targetContentOffsetCorrected.x) / Int(cellWidth)
        targetCellXCenter = (CGFloat(nextPlace) * cellWidth) + cellWidth
    }

    if targetCellXCenter != nil {
        targetContentOffset.memory.x = targetCellXCenter! - contentInsetX
    }
}

좋은 웹페이지 즐겨찾기