小编Ste*_*yne的帖子

iOS 9/Swift 2.0中的UIDynamics问题

好吧,所以我有一个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)
    }
Run Code Online (Sandbox Code Playgroud)

这两个块都会导致错误:

"'UIDynamicBehavior'类型的值没有成员'项''

然后我有:

    override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
       return self.dynamicAnimator.itemsInRect(rect)
    }
Run Code Online (Sandbox Code Playgroud)

产生错误:

"无法将'[UIDynamicItem]'类型的返回表达式转换为返回类型'[UICollectionViewLayoutAttributes]?' "

关于我如何转换这个的任何想法?我知道swift 2非常新,但是我无法在网上找到任何关于此的内容,就像我说的那样,关于UIKitDynamicBehavior的文档至少缺乏说明.在此先感谢您的帮助!

ios swift swift2

5
推荐指数
1
解决办法
499
查看次数

标签 统计

ios ×1

swift ×1

swift2 ×1