2015-09-29 2 views
5

Хорошо, поэтому у меня есть UICollectionViewFlowLayout, который поддерживает похожие на весну анимации при прокрутке, похожей на приложение сообщений iOS. В любом случае, при переходе на Swift 2.0, похоже, что UIDynamics полностью изменилась. Я пытаюсь преобразовать следующие блоки, но я просто не могу понять это, и документация Apple здесь ОЧЕНЬ несовместима. Следующие блоки должны быть преобразованы еще:Проблема с UIDynamics в iOS 9/Swift 2.0

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 
Смежные вопросы