pot*_*ato 9 collectionview ios uicollectionview uicollectionviewlayout
我做了一个子类collectionViewFlowLayout
.之后,我实现了以下代码:
override func finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attr = self.layoutAttributesForItemAtIndexPath(itemIndexPath)
attr?.transform = CGAffineTransformRotate(CGAffineTransformMakeScale(0.8, 0.8), CGFloat(M_PI))
attr?.center = CGPointMake(CGRectGetMidX(self.collectionView!.bounds), CGRectGetMidY(self.collectionView!.bounds))
return attr
}
Run Code Online (Sandbox Code Playgroud)
当我使用performBatchUpdates
:方法删除集合视图中的项时,调试器会抛出此错误消息.删除实际上成功并且完全正常工作,但我对此调试器输出有点困惑.有人可以解释我应该做什么来取悦调试器吗?我真的不明白什么代码和应该添加到哪里.
//错误信息
2015-08-02 12:39:42.208 nameOfMyProject [1888:51831]仅为UICollectionViewFlowLayout缓存不匹配帧记录一次2015-08-02 12:39:42.209 nameOfMyProject [1888:51831] UICollectionViewFlowLayout缓存了索引路径的帧不匹配{length = 2,path = 0 - 11} - 缓存值:{{106.13333333333333,131.13333333333333},{75.733333333333348,75.733333333333348}}; 预期值:{{192.5,288},{94.666666666666671,94.666666666666671}}
2015-08-02 12:39:42.209 nameOfMyProject [1888:51831]这可能是因为流布局子类nameOfMyProject.ShopLayout正在修改UICollectionViewFlowLayout返回的属性而不复制它们
2015-08-02 12:39:42.209 nameOfMyProject [1888:51831]快照未渲染的视图会导致空快照.确保在屏幕更新后快照或快照之前至少渲染了一次视图.
joe*_*ern 10
发生此错误的原因是您在不首先复制属性的情况下操作该属性.所以这应该修复错误:
override func finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attr = self.layoutAttributesForItemAtIndexPath(itemIndexPath)?.copy() as! UICollectionViewLayoutAttributes
// manipulate the attr
return attr
}
Run Code Online (Sandbox Code Playgroud)
当您遇到相同的错误时,layoutAttributesForElementsInRect(rect: CGRect)
您必须复制数组中的每个项目而不是仅复制数组:
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let attributes = super.layoutAttributesForElementsInRect(rect)
var attributesCopy = [UICollectionViewLayoutAttributes]()
for itemAttributes in attributes! {
let itemAttributesCopy = itemAttributes.copy() as! UICollectionViewLayoutAttributes
// manipulate itemAttributesCopy
attributesCopy.append(itemAttributesCopy)
}
return attributesCopy
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3372 次 |
最近记录: |