好吧所以我有一个UICollectionViewFlowLayout,它支持类似弹簧的动画,同时滚动类似于iOS消息应用程序。无论如何,在转换到Swift 2.0后,似乎UIDynamics已经彻底改变了。我正在尝试转换以下块,但我似乎无法弄明白,Apple的文档在这里非常不支持。以下块仍需转换:
var noLongerVisibleBehaviors = self.dynamicAnimator.behaviors.filter({behavior in
var currentlyVisible = itemsIndexPathsInVisibleRectSet.member(behavior.items![0].indexPath) != nil
return !currentlyVisible
})
for (index, obj) in noLongerVisibleBehaviors.enumerate() {
self.dynamicAnimator.removeBehavior(obj )
self.visibleIndexPathsSet.removeObject(obj.items![0].indexPath)
}
这两个块都会导致错误:
“类型'UIDynamicBehavior'的值没有成员'items'”
然后我有:
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
return self.dynamicAnimator.itemsInRect(rect)
}
产生错误:
“无法将'[UIDynamicItem]'类型的返回表达式转换为返回类型'[UICollectionViewLayoutAttributes]?' “
关于我如何转换这个的任何想法?我知道swift 2非常新,但我无法在网上找到任何关于此的内容,就像我说的那样,关于UIKitDynamicBehavior的文档至少缺乏说明。在此先感谢您的帮助!
答案 0 :(得分:4)
修复第一个阻止问题:
“
UIDynamicBehavior
”类型的值没有成员“商品”
let attachmentBehavior:UIAttachmentBehavior = behavior as! UIAttachmentBehavior
解决第二个问题:
无法将“
[UIDynamicItem]
”类型的返回表达式转换为返回类型“[UICollectionViewLayoutAttributes]?
”
return self.dynamicAnimator.itemsInRect(rect) as? [UICollectionViewLayoutAttributes]
答案 1 :(得分:0)
That got me so far, but now I get "Value of type 'UIDynamicItem' has no member 'indexPath'
I had to add this also
let item = attachmentBehavior.items[0] as! UICollectionViewLayoutAttributes