[英]UIDynamics Issue in iOS 9/ Swift 2.0
Alright so I have a UICollectionViewFlowLayout that supports spring-like animations while scrolling similar to the iOS messages app. 好吧,所以我有一个UICollectionViewFlowLayout支持类似弹簧的动画,同时滚动类似于iOS消息应用程序。 Anyway, upon converting to Swift 2.0, it seems that UIDynamics have completely changed.
无论如何,在转换到Swift 2.0后,似乎UIDynamics已经彻底改变了。 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.
我正在尝试转换以下块,但我似乎无法弄明白,Apple的文档在这里非常不支持。 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' "
“'UIDynamicBehavior'类型的值没有成员'项''
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]?'
“无法将'[UIDynamicItem]'类型的返回表达式转换为返回类型'[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.
我知道swift 2非常新,但我无法在网上找到任何关于此的内容,就像我说的那样,关于UIKitDynamicBehavior的文档至少缺乏说明。 Thanks in advance for your help!
在此先感谢您的帮助!
To fix the first block issue: 要修复第一个块问题:
Value of type '
UIDynamicBehavior
' has no member 'items'“
UIDynamicBehavior
”类型的值没有成员“items”
let attachmentBehavior:UIAttachmentBehavior = behavior as! UIAttachmentBehavior
To fix the second issue: 解决第二个问题:
Cannot convert return expression of type '
[UIDynamicItem]
' to return type '[UICollectionViewLayoutAttributes]?
无法将'
[UIDynamicItem]
'类型的返回表达式转换为返回类型'[UICollectionViewLayoutAttributes]?
'“
return self.dynamicAnimator.itemsInRect(rect) as? [UICollectionViewLayoutAttributes]
That got me so far, but now I get "Value of type 'UIDynamicItem' has no member 'indexPath' 这让我到目前为止,但现在我得到“类型'的价值'UIDynamicItem'没有成员'indexPath'
I had to add this also 我也必须加上这个
let item = attachmentBehavior.items[0] as! UICollectionViewLayoutAttributes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.