Um dies zu erreichen, müssen Sie UICollectionViewFlowLayout
Unterklasse und überschreiben:
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
dann super.layoutAt nennen ... und verändern die Zelle, um sie über seine .transform Attribut gibt und zurück Ihre geänderten Attribute
Hier ist ein Beispiel, das ich zuvor gemacht habe.
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
}
Hallo, Überprüfen Sie den Link und wählen, wenn es hilft. https://github.com/ink-spot/UPCarouselFlowLayout –
Das funktioniert super, wie kann ich diese Antwort akzeptieren? –
Wählen Sie einfach durch Drücken der Taste über Flag, Sie können beide finden, indem Sie den Mauszeiger auf meine Antwort bewegen. Vielen Dank. –