gpt4 book ai didi

swift - UICollectionViewTransitionLayout 和 contentOffset 完成

转载 作者:可可西里 更新时间:2023-11-01 00:59:03 29 4
gpt4 key购买 nike

当 UICollectionView 完成交互式转换时,它会滚动到意外的偏移量。在转换的完成 block 中设置 contentOffset 有帮助,但我在瞬间看到了相同的无效 contentOffset。无论是使用标准 UICollectionViewFlowLayout 还是自定义布局。有没有办法坚持下一个布局的单元格?我的代码示例

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")

更新:在开始时添加这段代码对我有帮助,但我需要在转换前不进行额外滚动的情况下执行转换

collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: UICollectionViewScrollPosition.CenteredVertically, animated: false)

“动画”标志应该是假的

最佳答案

我找到答案了!它需要覆盖目标布局中的 targetContentOffsetForProposedContentOffset(proposedContentOffset: CGPoint)!

关于swift - UICollectionViewTransitionLayout 和 contentOffset 完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38485115/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com