9

Ich machte eine Unterklasse von collectionViewFlowLayout. Danach setzte ich den folgenden Code:bei der Verwendung von subclassed collectionViewFlowLayout bekomme ich seltsam Fehler

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 
    } 

Wenn ich Artikel in Sammlung Ansicht löschen Verwendung performBatchUpdates: Methode der Debugger diese Fehlermeldung führt. Die Löschung ist tatsächlich erfolgreich und funktioniert vollständig, aber ich bin ein wenig verwirrt über diese Debugger-Ausgabe. Kann mir bitte jemand erklären, ob ich bitte Debugger mache? Ich verstehe nicht wirklich, welcher Code und wo hinzugefügt werden sollte.

// ERROR MESSAGE

2015-08-02 12:39:42.208 nameOfMyProject[1888:51831] Logging only once for UICollectionViewFlowLayout cache mismatched frame 2015-08-02 12:39:42.209 nameOfMyProject[1888:51831] UICollectionViewFlowLayout has cached frame mismatch for index path {length = 2, path = 0 - 11} - cached value: {{106.13333333333333, 131.13333333333333}, {75.733333333333348, 75.733333333333348}}; expected value: {{192.5, 288}, {94.666666666666671, 94.666666666666671}}

2015-08-02 12:39:42.209 nameOfMyProject[1888:51831] This is likely occurring because the flow layout subclass nameOfMyProject.ShopLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them

2015-08-02 12:39:42.209 nameOfMyProject[1888:51831] Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.

+0

Hat diese nur Start passiert mit Xcode 7? Etwas sehr Ähnliches passiert mir seit der Aktualisierung auf Xcode 7 (und der Installation von iOS9). Ich bin Obj-C, nicht schnell, aber der Fehler sagt dir, dass du die Attribute nicht kopierst, bevor du sie änderst. Ich habe versucht, etwas wie 'NSArray * allAttributesInArray = [[super layoutAttributesForElementsInRect: rect] copy];' vor der Manipulation, aber das scheint auch nicht zu funktionieren. – wanderingme

+0

Ich benutze nie Sammlungsansicht vor xcode 7. Ich endete mit einem einfachen alten flowLayout ohne Unterklasse, so kann ich nicht wirklich eine Antwort zur Verfügung stellen – brumbrum

+0

@wanderingme hast du herausgefunden, wie das zu lösen? Ich habe das gleiche und nichts hat geholfen, es zu lösen. – Solomiya

Antwort

9

Der Fehler tritt auf, weil Sie das Attribut manipulieren, ohne es vorher zu kopieren. So sollte dieser den Fehler beheben:

override func finalLayoutAttributesForDisappearingItemAtIndexPath(itemIndexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? { 
    let attr = self.layoutAttributesForItemAtIndexPath(itemIndexPath)?.copy() as! UICollectionViewLayoutAttributes 
    // manipulate the attr 
    return attr 
} 

Wenn Sie über den gleichen Fehler kommen in layoutAttributesForElementsInRect(rect: CGRect) Sie jedes der Elemente im Array zu kopieren, anstatt nur das Kopieren der Array:

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 
    } 
+0

Kopieren aller Attribute in layoutAttributesForElementsInRect löste die Warnungen. –

+0

@Joern, das funktioniert nicht – Ranjit

+0

@Ranjit Haben Sie sich das Github-Problem in den obigen Kommentaren angeschaut? (https://github.com/wtmoose/TLLayoutTransitioning/issues/26) – joern