2015-09-29 48 views
5

好吧,我有一個UICollectionViewFlowLayout,它支持類似於iOS消息應用程序的類似於彈簧的動畫。無論如何,在轉換到Swift 2.0後,似乎UIDynamics已經完全改變了。我試圖轉換下面的塊,但我似乎無法弄清楚,蘋果的文檔是非常不支持在這裏。以下塊需要被靜止轉換:iOS 9/Swift 2.0中的UIDynamics問題

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

這兩個塊的導致該錯誤:

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

然後,我有:

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

其產生錯誤:

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

任何想法我如何轉換這個?我知道swift 2是非常新的,但我無法在網上找到任何關於這個的東西,就像我說的那樣,關於UIKitDynamicBehavior的文檔至少沒有說。在此先感謝您的幫助!

回答

4

要解決的第一個塊問題:

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

let attachmentBehavior:UIAttachmentBehavior = behavior as! UIAttachmentBehavior 

要解決的第二個問題:

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

return self.dynamicAnimator.itemsInRect(rect) as? [UICollectionViewLayoutAttributes] 
0

這讓我那麼遠,但現在我得到「的價值類型'UIDynamicItem'沒有成員'indexPath'

我不得不dd這也

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