UIDynamics issue in iOS 9 / Swift 2.0

Ok, so I have a UICollectionViewFlowLayout that supports spring animations while scrolling like an iOS messaging app. In any case, when switching to Swift 2.0, it seems that UIDynamics has completely changed. I am trying to convert the following blocks, but I just can't figure it out, and the Apple documentation here is VERY incompatible. The following blocks still need to be converted:

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 an error:

"Value of type" UIDynamicBehavior "does not have elements of the element"

Then I:

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

which causes the error:

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

Any ideas on how I can convert this? I know that swift 2 is very new, but I can not find ANYTHING on the Internet regarding this and, as I said, the documentation for UIKitDynamicBehavior is at least missing. Thanks in advance for your help!

+5
source share
2 answers

To fix the problem of the first block:

A value of type ' UIDynamicBehavior ' has no member elements'

 let attachmentBehavior:UIAttachmentBehavior = behavior as! UIAttachmentBehavior 

To fix the second problem:

Can't convert the returned expression of type ' [UIDynamicItem] ' to return the type of ' [UICollectionViewLayoutAttributes]? ''

 return self.dynamicAnimator.itemsInRect(rect) as? [UICollectionViewLayoutAttributes] 
+4
source

It came to me, but now I get a "Value of type" UIDynamicItem "does not have an element of" indexPath "

I had to add this as well

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

Source: https://habr.com/ru/post/1232549/


All Articles