5
"etki alanına eklemeye" çalışıyorum ancak çalışamadım, yanlış yaptığım bir şey var mı?hızlı konumlandırma merkezi UICollectionViewCell
Subclassing UICollectionViewFlowLayout
ve ağır basan targetContentOffsetForProposedContentOffset
fonksiyonu:
override func targetContentOffsetForProposedContentOffset(proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
var offsetAdjustment:CGFloat = CGFloat(MAXFLOAT)
let verticalCenter:CGFloat = proposedContentOffset.y + (CGRectGetHeight(self.collectionView!.bounds)/2.0)
let proposedRect:CGRect = CGRectMake(proposedContentOffset.x,0.0,self.collectionView!.bounds.size.width,self.collectionView!.bounds.size.height)
let array:NSArray = self.layoutAttributesForElementsInRect(proposedRect)!
for layoutAttributes : AnyObject in array {
if let _layoutAttributes = layoutAttributes as? UICollectionViewLayoutAttributes {
if _layoutAttributes.representedElementCategory != UICollectionElementCategory.Cell {
continue
}
let itemVerticalCenter:CGFloat = layoutAttributes.center.y
let _verticalCenter = fabsf(Float(itemVerticalCenter) - Float(verticalCenter))
let _offsetAdjustment = fabsf(Float(offsetAdjustment))
if (_verticalCenter < _offsetAdjustment) {
offsetAdjustment = itemVerticalCenter - verticalCenter
}
}
}
return CGPointMake(proposedContentOffset.x + offsetAdjustment, proposedContentOffset.y)
}
Sample project here ve snap effect, desired output