4
私は、セルがお互いの上に重なるカスタムUICollectionView + Layoutに取り組んでいます。さらに、アイテムの追加や削除のためのカスタムアニメーションを実装しています。オーバラップセルとカスタム挿入アニメーションと削除アニメーションを持つUICollectionView
項目の挿入/削除中に属性のプロパティーのうちzIndex
のプロパティが無視されるようであることを除いて、すべて正常に機能しています。
はここでカスタム挿入/削除のアニメーションのための私の実装です。私の推測は、問題はこれらの方法のどこかにあることです。
override func initialLayoutAttributesForAppearingItemAtIndexPath(itemIndexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attributes = layoutAttributesForItemAtIndexPath(itemIndexPath)
for updateItem in updateItems {
switch updateItem.updateAction {
case .Insert:
if updateItem.indexPathAfterUpdate == itemIndexPath {
let translation = collectionView!.bounds.height
attributes?.transform = CGAffineTransformMakeTranslation(0, translation)
break
}
default:
break
}
}
return attributes
}
override func finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
for updateItem in updateItems {
switch updateItem.updateAction {
case .Delete:
if updateItem.indexPathBeforeUpdate == itemIndexPath {
let attributes = layoutAttributesForItemAtIndexPath(itemIndexPath)
let translation = collectionView!.bounds.height
attributes?.transform = CGAffineTransformMakeTranslation(0, translation)
return attributes
}
case .Move:
if updateItem.indexPathBeforeUpdate == itemIndexPath {
return layoutAttributesForItemAtIndexPath(updateItem.indexPathAfterUpdate!)
}
default:
break
}
}
let finalIndex = finalIndexForIndexPath(itemIndexPath)
let shiftedIndexPath = NSIndexPath(forItem: finalIndex, inSection: itemIndexPath.section)
return layoutAttributesForItemAtIndexPath(shiftedIndexPath)
}
private func finalIndexForIndexPath(indexPath: NSIndexPath) -> Int {
var newIndex = indexPath.item
for updateItem in updateItems {
switch updateItem.updateAction {
case .Insert:
if updateItem.indexPathAfterUpdate!.item <= newIndex {
newIndex += 1
}
case .Delete:
if updateItem.indexPathBeforeUpdate!.item < newIndex {
newIndex -= 1
}
case .Move:
if updateItem.indexPathBeforeUpdate!.item < newIndex {
newIndex -= 1
}
if updateItem.indexPathAfterUpdate!.item <= newIndex {
newIndex += 1
}
default:
break
}
}
return newIndex
}
物事は私が試してみた:
- はそれがになってしまうだろう値に
initialLayoutAttributes...
方法でzIndex
を設定します。 - アニメーションの後でコレクションビューを手動で並べ替える(これはかなりハッキーですが、これは避けることをお勧めします。
super.initialLayoutAttributes...
などを呼び出して、それから返される属性を変更します。その問題は、新しいセルが挿入されたときに他のセルが移動するのを処理しないことです。代わりに、セルがフェードインまたはフェードアウトします。
プロジェクトの小さな再生者はmy GitHubにあります。それを複製して遊んでみてください。
Hey Mark、私はカスタムオーバーラップコレクションビューセルのこの種の必要があります。このカスタムコレクションビューは、Cocoapodライブラリ形式でインストールして使用できますか? – Zhang
うん、ここに私のレポがある:https://github.com/mpdifran/OverlapCollectionView – Mark
私はスタンドアロンのCocoapodパッケージをもっと考えていた。ポッドファイルに追加してポッドインストールを実行し、抽出するのではなく独自のアプリで使い始めることができる関連するコードを既存のプロジェクトから外してください:DIは、他の人が恩恵を受けることができる非常に便利なライブラリになると考えています。 – Zhang