chiahsien / CHTCollectionViewWaterfallLayout

The waterfall (i.e., Pinterest-like) layout for UICollectionView.
MIT License
4.54k stars 701 forks source link

Strange image and layout behavior. #106

Closed Neogene closed 9 years ago

Neogene commented 9 years ago

Hi, we are facing a strange behavior:

we use two CHTCollectionViewWaterfallCell in the Storyboard, one of them uses an uiimageview, and both have different sizes.

The issue we are facing is some images aren't loaded, in other cases the size of the CHTCollectionViewWaterfallCell is not updated and uses the size of the other cell.

Inizialization:

CHTCollectionViewWaterfallLayout *layout =
(CHTCollectionViewWaterfallLayout *)self.collection.collectionViewLayout;
layout.minimumColumnSpacing=10.0;
layout.minimumInteritemSpacing=10.0;
layout.itemRenderDirection=CHTCollectionViewWaterfallLayoutItemRenderDirectionLeftToRight;

Layout:

The size detection code is the same for both the methods, checking the existence of the image from an nsarray.

Image is set properly but seems a refresh error, we tried chaning uiimageview size and calling setneeddisplay etc.

Dragging below and going back causes the cell to be refreshed and the image displayed properly.

Regarding size the problem is also really strange.

Any help appreciated.

Attahched images of missing loaded image

1st image: the second box in the second column isn't updated regarding size. 2nd image: box without image loaded, when scrolling and going back the image is displayed.

schermata 2015-08-10 alle 22 21 15 schermata 2015-08-10 alle 22 21 05

Neogene commented 9 years ago

Here a log of layoutattributesforelementsinrect: which returns

(column 1 element 0): frame = (254 0; 244 379); , but is displayed with the wrong size. (column 2 element 0): frame = (254 389; 244 379); same behavior correct size but wrong displayed size.

schermata 2015-08-11 alle 08 09 46

chiahsien commented 9 years ago

Do you use CHTCollectionViewWaterfallCell? This class is for demo purpose, don't use it in your project.

I don't know how you construct your collection view cell, maybe there's an imageview layout issue in it. You can try to:

Neogene commented 9 years ago

Ok sorry, my mistake i use BOOL img = [UIImage imageNamed:...] using from years the knowledge 0 = NO and other values are YES, but in this case it get a random value which sometimes is evaluated as NO/YES randomly! Closing because is not an issue ! Thank you for the support.