Strange disappearing items when scrolls
U

2

8

Presets,

i have collectionViewFlowLayout subclass with

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
    return YES;
   }

- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
    NSArray *arr = [super layoutAttributesForElementsInRect:rect];
    BBLog(@"ARRA:%@", arr);
    for (UICollectionViewLayoutAttributes *attr in arr) {
        if (CGAffineTransformIsIdentity(attr.transform)) {
            attr.transform = CGAffineTransformMakeRotation((CGFloat)M_PI);
        }
    }

    return arr;
}

CollectionView rotate to upside down scroll with

 self.collectionView.transform = CGAffineTransformMakeRotation((CGFloat)M_PI);

But even if jus use native collectionViewFlowLayout without subclassing, a git this error

Problem

I have two messages and more in chat, but when scroll at bottom (top normally) disappear second item.

layoutAttributesForElementsInRect for given rect return two attributes for two indexPaths 0-0 and 0-1, but delegate method

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

called only for indexPath 0-0

Here images

TopScroll enter image description here

UPDATE So i found WHY it's happen - this line code

attr.transform = CGAffineTransformMakeRotation((CGFloat)M_PI);

Look if remove transform

enter image description here

Unreadable answered 19/1, 2016 at 13:15 Comment(0)
U
0

Sorry, all, but i found reason and work around.

This happen only on device not on simulator

Look at three CGRects

iPhone 5S

(CGRect) oldFrame = (origin = (x = -0.000000000000056843418860808015, y = 0), size = (width = 320.00000000000006, height = 314.00000000000006))

iPhone 5C

(CGRect) oldFrame = (origin = (x = 0, y = 0), size = (width = 320, height = 314))

Simulator Intel Core

(CGRect) oldFrame = (origin = (x = 0, y = 0), size = (width = 320, height = 314))

To all of them i apply rotation transform via

CGAffineTransformMakeRotation((CGFloat)M_PI)

First it's on iPhone 5S ARM Apple A7 CPU

Second it's on iPhone 5C ARM Apple A6 CPU

Third it's on Simulator at Intel Core iX processor.

So, my work around is:

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewLayoutAttributes *retAttr = [super layoutAttributesForItemAtIndexPath:indexPath];

    if (CGAffineTransformIsIdentity(retAttr.transform)) {
        retAttr.transform = CGAffineTransformMakeRotation((CGFloat)M_PI);
    }

    CGRect oldFrame = retAttr.frame;

    oldFrame.origin.x = retAttr.frame.origin.x > 0 ?: 0;

    retAttr.frame = oldFrame;

    return retAttr;
}
Unreadable answered 19/1, 2016 at 13:15 Comment(2)
any solution for swift ?Vowelize
In swift did not test, now coding only in objc. But i think same problem will be.Unreadable
C
1

I am not entirely sure, but I think that, when You are subclassing the UICollectionViewFlowLayout, You are not supposed to modify the attributes directly, but to make a copy of the attributes, modify it instead and return it.

Short explanation of the top statement : You will have to subclass the UICollectionViewFlowDelegate ( the parent of UICollectionViewDelegateFlowLayout ) and than make your own attributes and modify them as You wish, but this will require of to implement a lot more custom logic.

Also look if You are getting any errors or warnings in the console.

Check out this question : Warning: UICollectionViewFlowLayout has cached frame mismatch for index path 'abc'

Hope that I was at least a little helpful.

Clevey answered 5/2, 2016 at 15:44 Comment(0)
U
0

Sorry, all, but i found reason and work around.

This happen only on device not on simulator

Look at three CGRects

iPhone 5S

(CGRect) oldFrame = (origin = (x = -0.000000000000056843418860808015, y = 0), size = (width = 320.00000000000006, height = 314.00000000000006))

iPhone 5C

(CGRect) oldFrame = (origin = (x = 0, y = 0), size = (width = 320, height = 314))

Simulator Intel Core

(CGRect) oldFrame = (origin = (x = 0, y = 0), size = (width = 320, height = 314))

To all of them i apply rotation transform via

CGAffineTransformMakeRotation((CGFloat)M_PI)

First it's on iPhone 5S ARM Apple A7 CPU

Second it's on iPhone 5C ARM Apple A6 CPU

Third it's on Simulator at Intel Core iX processor.

So, my work around is:

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewLayoutAttributes *retAttr = [super layoutAttributesForItemAtIndexPath:indexPath];

    if (CGAffineTransformIsIdentity(retAttr.transform)) {
        retAttr.transform = CGAffineTransformMakeRotation((CGFloat)M_PI);
    }

    CGRect oldFrame = retAttr.frame;

    oldFrame.origin.x = retAttr.frame.origin.x > 0 ?: 0;

    retAttr.frame = oldFrame;

    return retAttr;
}
Unreadable answered 19/1, 2016 at 13:15 Comment(2)
any solution for swift ?Vowelize
In swift did not test, now coding only in objc. But i think same problem will be.Unreadable

© 2022 - 2024 — McMap. All rights reserved.