Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIDynamics Issue in iOS 9/ Swift 2.0

Tags:

ios

swift

swift2

Alright so I have a UICollectionViewFlowLayout that supports spring-like animations while scrolling similar to the iOS messages app. Anyway, upon converting to Swift 2.0, it seems that UIDynamics have completely changed. I'm trying to convert the following blocks but I just can't seem to figure it out and Apple's documentation is VERY unsupportive here. The following blocks need to be converted still:

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

Both of these blocks cause the error:

"Value of type 'UIDynamicBehavior' has no member 'items' "

Then I have:

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

which produces the error:

"Cannot convert return expression of type '[UIDynamicItem]' to return type '[UICollectionViewLayoutAttributes]?' "

Any ideas on how I can convert this? I know swift 2 is very new but I can't find ANYTHING online regarding this and like I said, the documentation on UIKitDynamicBehavior is lacking to say the least. Thanks in advance for your help!

like image 772
Steve Payne Avatar asked Sep 27 '22 14:09

Steve Payne


1 Answers

To fix the first block issue:

Value of type 'UIDynamicBehavior' has no member 'items'

let attachmentBehavior:UIAttachmentBehavior = behavior as! UIAttachmentBehavior

To fix the second issue:

Cannot convert return expression of type '[UIDynamicItem]' to return type '[UICollectionViewLayoutAttributes]?'

return self.dynamicAnimator.itemsInRect(rect) as? [UICollectionViewLayoutAttributes]
like image 131
jamylak Avatar answered Sep 30 '22 08:09

jamylak