iOS 9/Swift 2.0中UIDynamics问题

5

好的,我有一个支持类似于iOS消息应用程序的弹簧式滚动动画的UICollectionViewFlowLayout。 但是,在转换为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的文档缺乏。提前感谢您的帮助!

2个回答

4
为解决第一个块问题:

类型 'UIDynamicBehavior' 的值没有成员 'items'

let attachmentBehavior:UIAttachmentBehavior = behavior as! UIAttachmentBehavior

为了解决第二个问题:
无法将类型为 '[UIDynamicItem]' 的返回表达式转换为返回类型 '[UICollectionViewLayoutAttributes]?'
return self.dynamicAnimator.itemsInRect(rect) as? [UICollectionViewLayoutAttributes]

0

这让我有了一定的进展,但现在出现了“UIDynamicItem类型的值没有成员'indexPath'”

我也不得不添加这个

let item = attachmentBehavior.items[0] as! UICollectionViewLayoutAttributes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接