2
UICollectionViewがインタラクティブトランジションを終了すると、予期しないオフセットにスクロールします。移行の完了ブロックにcontentOffsetを設定すると役立ちますが、同じ無効なcontentOffsetが分割秒で表示されます。 UICollectionViewFlowLayoutやカスタムレイアウトを使用しても問題ありません。次のレイアウトのためにセルに固執する方法はありますか?私のコード例では、UICollectionViewTransitionLayoutおよび終了時のcontentOffset
let nextLayout = self.collectionView.collectionViewLayout === layout1 ? layout2 : layout1
let transition = collectionView.startInteractiveTransitionToCollectionViewLayout(nextLayout) { (par1: Bool, par2: Bool) in
//There was contentOffset setting code, that leads to blink
}
let initializer:(POPMutableAnimatableProperty!)->Void = {property in
property.readBlock = {obj, values in
values[0] = transition.transitionProgress
}
property.writeBlock = {obj, values in
transition.transitionProgress = values[0]
if let attrs: UICollectionViewLayoutAttributes = transition.layoutAttributesForItemAtIndexPath(indexPath) {
collectionView.contentOffset = CGPointMake(attrs.frame.origin.x, attrs.frame.origin.y)
}
}
property.threshold = 0.01
}
let springAnimation = POPSpringAnimation()
let property = POPAnimatableProperty.propertyWithName("com.pop.property", initializer: initializer) as! POPAnimatableProperty
springAnimation.springBounciness = 8.0
springAnimation.dynamicsMass = 8.0
springAnimation.property = property
springAnimation.fromValue = 0.0
springAnimation.toValue = 1.0
springAnimation.completionBlock = {anim, finished in
if finished {
transition.transitionProgress = 1.0
self.collectionView.finishInteractiveTransition()
}
}
transition.pop_addAnimation(springAnimation, forKey: "transitionProgress")
UPDATE:開始時にこのコードを追加する が助けてくれたが、私は
collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: UICollectionViewScrollPosition.CenteredVertically, animated: false)
「アニメーション」フラグが偽であるべき移行する前に、追加のスクロールせずに移行を実行する必要が