警告:UICollectionViewFlowLayout 已缓存索引路径“abc"的帧不匹配 [英] Warning: UICollectionViewFlowLayout has cached frame mismatch for index path 'abc'

查看:11
本文介绍了警告:UICollectionViewFlowLayout 已缓存索引路径“abc"的帧不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是导致警告的代码:

private override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
    let attributes = super.layoutAttributesForItemAtIndexPath(indexPath)
    let distance = CGRectGetMidX(attributes!.frame) - self.midX;
    var transform = CATransform3DIdentity;
    transform = CATransform3DTranslate(transform, -distance, 0, -self.width);
    attributes!.transform3D = CATransform3DIdentity;
    return attributes
}

控制台也会打印:

这可能是因为流布局xyz"正在修改 UICollectionViewFlowLayout 返回的属性而不复制它们.

This is likely occurring because the flow layout "xyz" is modifying attributes returned by UICollectionViewFlowLayout without copying them.

如何解决此警告?

推荐答案

这很可能是因为流布局xyz"正在修改 UICollectionViewFlowLayout 返回的属性而不复制它们

This is likely occurring because the flow layout "xyz" is modifying attributes returned by UICollectionViewFlowLayout without copying them

果然,这正是你正在做的:

And sure enough, that's just what you are doing:

private override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
    let attributes = super.layoutAttributesForItemAtIndexPath(indexPath)
    let distance = CGRectGetMidX(attributes!.frame) - self.midX;
    var transform = CATransform3DIdentity;
    transform = CATransform3DTranslate(transform, -distance, 0, -self.width);
    attributes!.transform3D = CATransform3DIdentity;
    return attributes
}

我希望如果你简单地说:

I expect that if you simply say:

let attributes = 
    super.layoutAttributesForItemAtIndexPath(indexPath).copy() 
    as! UICollectionViewLayoutAttributes

或类似的,问题就会消失.

or similar, the problem will go away.

这篇关于警告:UICollectionViewFlowLayout 已缓存索引路径“abc"的帧不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆