Coder Social home page Coder Social logo

chiahsien / chtcollectionviewwaterfalllayout Goto Github PK

View Code? Open in Web Editor NEW
4.5K 130.0 699.0 21.38 MB

The waterfall (i.e., Pinterest-like) layout for UICollectionView.

License: MIT License

Swift 34.39% Objective-C 63.72% Ruby 1.89%
uicollectionview pinterest uicollectionviewlayout waterfall-layout

chtcollectionviewwaterfalllayout's Introduction

CHTCollectionViewWaterfallLayout

Carthage compatible Swift Package Manager compatible Version Platform Build Status

CHTCollectionViewWaterfallLayout is a subclass of UICollectionViewLayout, and it trys to imitate UICollectionViewFlowLayout's usage as much as possible.

This layout is inspired by Pinterest.

Screen Shots

2 columns

Features

  • Easy to use, it tries to imitate UICollectionViewFlowLayout's usage as much as possible.
  • Highly customizable.
  • Outstanding performance, try 10,000+ items and see the smoothness for yourself.
  • Support header and footer views.
  • Different column counts in different sections.

Requirements

  • iOS 9+ / tvOS 9+
  • Objective-C or Swift 4.2

How to install

  • CocoaPods

    • Add pod 'CHTCollectionViewWaterfallLayout' to your Podfile.
    • If you prefer Objective-C, pod 'CHTCollectionViewWaterfallLayout/ObjC' is ready for you.
  • Carthage

    • Add github chiahsien/CHTCollectionViewWaterfallLayout to your Cartfile.
  • Swift Package Manager

    • Add it to the dependencies value of your Package.swift.
    dependencies: [
      .package(url: "https://github.com/chiahsien/CHTCollectionViewWaterfallLayout.git", from: "0.9.9")
    ]
    
  • Manual

    • Copy CHTCollectionViewWaterfallLayout.h/m or CHTCollectionViewWaterfallLayout.swift to your project.

How to Use

Read the demo codes and CHTCollectionViewWaterfallLayout.h header file for more information.

Step 1

Below lists the properties for you to customize the layout. Although they have default values, I strongly recommend you to set up at least the columnCount property to suit your needs. The itemRenderDirection property is an enum which decides the order in which your items will be rendered in subsequent rows. For eg. Left-Right | Right-Left | Shortest column filling up first.

@property (nonatomic, assign) NSInteger columnCount;
@property (nonatomic, assign) CGFloat minimumColumnSpacing;
@property (nonatomic, assign) CGFloat minimumInteritemSpacing;
@property (nonatomic, assign) CGFloat headerHeight;
@property (nonatomic, assign) CGFloat footerHeight;
@property (nonatomic, assign) UIEdgeInsets sectionInset;
@property (nonatomic, assign) ItemRenderDirection itemRenderDirection;

Step 2

Your collection view's delegate (which often is your view controller) must conforms to CHTCollectionViewDelegateWaterfallLayout protocol and implements the required method, all you need to do is return the original size of the item:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;

Limitation

  • Only vertical scrolling is supported.
  • No decoration view.

Who is using it

Please let me know if your app is using this library. I'm glad to put your app on the list :-)

  • F3PiX F3PiX is a series of apps which gives you a concise, curated collection of pictures by professional (Dutch) photographers according to a specific theme. You can use the pictures freely for your own work.
  • GroupMe for iOS GroupMe - A Home for All the Groups in Your Life.
  • Flickr Access and organize your photos from anywhere.
  • Tumblr Post whatever you want to your Tumblr. Follow other people who are doing the same. You’ll probably never be bored again.
  • Funliday The best trip planning app in the world!
  • Imgur Funny GIFs, Memes, and Images!
  • DealPad DealPad gives you access to the UK’s hottest Deals, Voucher Codes and Freebies in the palm of your hand.
  • Teespring Shopping Browse and purchase shirts, mugs, totes and more!

License

CHTCollectionViewWaterfallLayout is available under the MIT license. See the LICENSE file for more info.

Changelog

Refer to the Releases page.

chtcollectionviewwaterfalllayout's People

Contributors

allevato avatar apollozhu avatar bm-i avatar bogidon avatar boradori avatar cbowns avatar ccwasden avatar chiahsien avatar demonnico avatar dlackty avatar flagoworld avatar jamztang avatar master-nevi avatar neilkimmett avatar olivercameron avatar przytua avatar rafaelcr avatar sebastiankumor avatar sfader avatar tcirwin avatar timkettering avatar tomcarey avatar u1tkzw avatar vvit avatar wcbyrne avatar wpk avatar yanamura avatar ywinters avatar yydd avatar zdavison avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chtcollectionviewwaterfalllayout's Issues

Crashes as soon as I add autolayout constraints on storyboard

If I add Layout constraints I get the following error:

2014-07-20 22:07:48.231 cookpad-global-ios[4182:86745] -[UILabel length]: unrecognized selector sent to instance 0x7f9b5a5ac9f0
2014-07-20 22:07:48.235 cookpad-global-ios[4182:86745] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel length]: unrecognized selector sent to instance 0x7f9b5a5ac9f0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010f493055 exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010f140a1c objc_exception_throw + 45
2 CoreFoundation 0x000000010f499f1d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010f3f2dbc __forwarding
+ 988
4 CoreFoundation 0x000000010f3f2958 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010e0cdee1 _truncatedDebuggingDescriptionForLayout + 23
6 UIKit 0x000000010e0da44e -[UIView(AdditionalLayoutSupport) _defaultLayoutDescription] + 39
7 Foundation 0x000000010ee724d4 descriptionForLayoutAttribute_layoutItem_coefficient + 92
8 Foundation 0x000000010ee722f9 -[NSLayoutConstraint equationDescription] + 77
9 Foundation 0x000000010ee727f8 -[NSLayoutConstraint description] + 284
10 CoreFoundation 0x000000010f4853a6 -[NSArray descriptionWithLocale:indent:] + 358
11 Foundation 0x000000010ecbd5f6 _NSDescriptionWithLocaleFunc + 64
12 CoreFoundation 0x000000010f38e7fd __CFStringAppendFormatCore + 9645
13 CoreFoundation 0x000000010f473720 _CFStringCreateWithFormatAndArgumentsAux2 + 256
14 CoreFoundation 0x000000010f4826df _CFLogvEx2 + 127
15 Foundation 0x000000010ece3de2 NSLogv + 99
16 Foundation 0x000000010ece3d67 NSLog + 148
17 Foundation 0x000000010ee6c23f -[NSISEngine handleUnsatisfiableRowWithHead:body:usingInfeasibilityHandlingBehavior:mutuallyExclusiveConstraints:] + 492
18 Foundation 0x000000010ee6c964 -[NSISEngine tryUsingArtificialVariableToAddConstraintWithMarker:rowBody:usingInfeasibilityHandlingBehavior:mutuallyExclusiveConstraints:] + 382
19 Foundation 0x000000010eced8aa -[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:] + 691
20 Foundation 0x000000010ee731bb -[NSLayoutConstraint _addLoweredExpression:toEngine:integralizationAdjustment:lastLoweredConstantWasRounded:mutuallyExclusiveConstraints:] + 275
21 Foundation 0x000000010ece1f3d -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 220
22 UIKit 0x000000010e0ce69a -[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 462
23 UIKit 0x000000010e0ce934 -[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:] + 30
24 UIKit 0x000000010e0cea5c -[UIView(UIConstraintBasedLayout) _tryToAddConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 243
25 UIKit 0x000000010e0ced9b __50-[UIView(UIConstraintBasedLayout) addConstraints:]_block_invoke + 188
26 Foundation 0x000000010ecefd29 -[NSISEngine withBehaviors:performModifications:] + 150
27 UIKit 0x000000010e0cecd0 -[UIView(UIConstraintBasedLayout) addConstraints:] + 263
28 UIKit 0x000000010e0d0219 -[UIView(UIConstraintBasedLayout) _updateLayoutEngineHostConstraints] + 492
29 UIKit 0x000000010e0da1b8 -[UIView(AdditionalLayoutSupport) updateConstraints] + 43
30 UIKit 0x000000010e0d971a -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 243
31 Foundation 0x000000010ecefd29 -[NSISEngine withBehaviors:performModifications:] + 150
32 UIKit 0x000000010e0d991a -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124
33 UIKit 0x000000010e0d9dde __60-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]_block_invoke + 96
34 Foundation 0x000000010ecefd29 -[NSISEngine withBehaviors:performModifications:] + 150
35 UIKit 0x000000010e0d9aa6 -[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded] + 231
36 UIKit 0x000000010e0da308 -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeeded] + 159
37 UIKit 0x000000010dada22d -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 114
38 UIKit 0x000000010dae5ebd -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 519
39 QuartzCore 0x000000010f973598 -[CALayer layoutSublayers] + 150
40 QuartzCore 0x000000010f9681be _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
41 QuartzCore 0x000000010f96802e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
42 QuartzCore 0x000000010f8d6f16 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
43 QuartzCore 0x000000010f8d8022 _ZN2CA11Transaction6commitEv + 390
44 QuartzCore 0x000000010f8d868d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
45 CoreFoundation 0x000000010f3c8927 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23
46 CoreFoundation 0x000000010f3c8880 __CFRunLoopDoObservers + 368
47 CoreFoundation 0x000000010f3be0d3 __CFRunLoopRun + 1123
48 CoreFoundation 0x000000010f3bda06 CFRunLoopRunSpecific + 470
49 GraphicsServices 0x0000000112402abf GSEventRunModal + 161
50 UIKit 0x000000010da6dcf8 UIApplicationMain + 1282
51 cookpad-global-ios 0x000000010d36ca63 main + 115
52 libdyld.dylib 0x000000010fd29145 start + 1
53 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

As soon as I remove all constraints it works great, but then the texts inside my cell are not well aligned.

Strange Rendering Bug

There seem to be a bug with CHTCollectionViewWaterfallLayout when rendering a comparatively small number of items.

You should be able to replicate this with the Demo project by changing the CELL_COUNT constant in ViewController.m, from 30000 to something small, e.g. 21.

There are actually 2 bugs:

Bug #1: layout would crash with any number that's not a multiple of unionSize (20). For example, use the above example of 21. This is due to a lack of bounds checking in layoutAttributesForElementsInRect:(CGRect)rect

this can be fixed by changing line 160 in CHTCollectionViewWaterfallLayout.m from:
for (i = begin; i < end; i++)
to
for (i = begin; i < end && i<self.itemAttributes.count; i++)

Bug #2: for small values of CELL_COUNT, roughly 10 cells starting at index ceil(CELL_COUNT/union_size) would be blank, and then continue correctly afterwards. For example, if you set CELL_COUNT to 141, then cell #0-#7 would be rendered correctly, then cells 8-15 would be blank, and then everything renders well afterwards. I have yet to figure out why this is.

Dynamically change columnCount

Hi and thanks for this amazing lib,

I try to dynamically change columnCount property of the layout to obtain something like :
capture decran 2014-06-05 a 13 07 10

Any idea how I can achieve this ?

rotating issue

when rotating, there's a warning log:

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.

gettinig crash when using with non ARC

It is working fine with ARC.
When i disable the arc it gives following error
@synthesize of 'weak' property is only allowed in ARC or GC mode
So i change the following in CHTCollectionViewWaterfallLayout.m
@Property (nonatomic, weak) id delegate;
with
@Property (nonatomic, assign) id delegate.
No error at build time but it is getting crash at
[self.headersAttribute removeAllObjects];
in CHTCollectionViewWaterfallLayout.m.

I added the flag -fno-objc-arc in Build Phases---> Compile Sources.
Still it is getting crash. please help ?

Async Image Loader

I can't get this to work with an Async Image Loader for the Cells, or for resizing text labels to sizeToFit.

I am using SDWebImage for async image loading.

I am also trying to get a 'load more' button to take up the full width which also seems quite difficult

How to get the dynamic height from a image fetched from internet

I know I have to implement heightForRow method. But, in your demo, the height is saved in an array. But I am getting the image from internet, and the height varies. How to calc the height of the row for some indexpaht. and layout the collection view automatic? I know it's irrelevant. But could somebody help me with this?

Items are loading in random order

The cards that are being rendered are not in the order of my data array.
For eg.:
. _ _ _ _ _ .
| |1| |2| |3| |
| |5| |6| |4| |
| |8| |9| |7| |
|_ _ _ _ _ .|

(apologies for the poor ASCII)

Do I have to set any property to fix this? I was expecting them to render left-right in each row:

1 2 3
4 5 6
7 8 9 ...

Single column inter item spacing causes divide by zero and error

I get the error 2013-10-30 13:34:05.666 Channel4000[678:60b] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan -inf]'

It's caused by _interitemSpacing = floorf((width - _columnCount * _itemWidth) / (_columnCount - 1));

The result of the divide by zero must make its way into the position of a layer. It can be fixed by:

_interitemSpacing = (_columnCount <= 1) ? 0.0f : floorf((width - _columnCount * _itemWidth) / (_columnCount - 1));

numberOfSectionsInCollectionView does not work

Hi, I try to implement the delegate in the demo.xcodeproj but it does not work (called but not work, it just show 1 section)

  • (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 2;
    }

Variable Width

Is there a way to use this with different width collection view cells?

UI* prefix is reserved by UIKit

Its generally considered good practice to use your own two/three letter prefix - should Apple introduce a UICollectionViewWaterfallLayout class in a future release of iOS, this will cause issues. Besides that, its generally helpful to have a unique prefix so there is no confusion around the origin of the class - using the UI prefix gives the impression that this is a native UIKit class.

Build Demo failed

I get build error

The document "MainStoryboard_iPhone.storyboard" could not be opened. Could not read archive.
Please use a newer version of Xcode. Consider changing the document's Development Target to preserve compatibility.

I am opening it in ios 6 and xcode 4.6.3

Compliments and praise

Hi! I used your Waterfall Layout in my app F3PiX. Thanks! Works like a charm.
(Is this the right place for praise?)

Calling reloadData in cellForItemAtIndexPath method brings some strange behavior.

Calling reloadData in cellForItemAtIndexPath method most items, and cellForItemAtIndexPath is not called again.
Can't find out why but if calling reloadData with dispatch_async , then everything is ok.

Here is a code snippet , just change in viewcontroller this method:

BOOL reloaded = NO;

  • (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
    cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
    UICollectionViewWaterfallCell *cell =
    (UICollectionViewWaterfallCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CELL_IDENTIFIER
    forIndexPath:indexPath];

    cell.displayString = [NSString stringWithFormat:@"%d", indexPath.row];
    if (indexPath.row == CELL_COUNT - 2 && !reloaded) {

    reloaded = YES;
    

    // dispatch_async(dispatch_get_main_queue(), ^{
    [self.collectionView reloadData];
    // });
    }
    return cell;
    }

iPhone 6's 375 point width can cause 1px margin on right side

The app I am developing uses two columns of content. Both are the same width and separated by a 10px column. It should layout from edge to edge, and on all devices tested, it does layout edge-to-edge, but on iphone 6, a 1px margin showing the view background was observed.

Looking at the code, (the swift version), it seems that the item width is calculated here:

https://github.com/chiahsien/CHTCollectionViewWaterfallLayout/blob/develop/CHTCollectionViewWaterfallLayout.swift#L171

i realized that the iphone 6 is the only device with a odd-numbered width (375). all other ios devices have evenly divisible widths. 320, 414, and 768...

so the use of floor() to drop the result of the division works fine for all ios devices, but on iphone 6, it results in the sum of item width, insets and columns to be 1-2px less than the actual screen width.

removing the floor() function and allowing the CGFloat to be a decimal place works for all devices i test on, but i am not submitting a PR with this fix because I do not know what your intentions were for using floor() and what other issues that may bring up. So I am just opening this issue for further discussion/consideration.

Thanks!

Create a Cocoapods Podspec

Hi,

It would be nice to have a Cocoapods Podspec file for this project.

To create one, see: https://github.com/CocoaPods/Specs/blob/master/README.md

The following would already work as a Podspec file, although it is recommended to create semantic version tags (see the README linked above):

Pod::Spec.new do |s|
  s.name         = "CHTCollectionViewWaterfallLayout"
  s.version      = "0.0.1"
  s.summary      = "The waterfall (i.e., Pinterest-like) layout for UICollectionView introduced in iOS 6."
  s.homepage     = "https://github.com/chiahsien/CHTCollectionViewWaterfallLayout"
  s.screenshots  = "https://raw.github.com/chiahsien/UICollectionViewWaterfallLayout/master/Screenshots/2-columns.png", "https://raw.github.com/chiahsien/UICollectionViewWaterfallLayout/master/Screenshots/3-columns.png"
  s.license      = 'MIT'
  s.author       = { "Nelson" => "[email protected]>" }
  s.source       = { :git => "https://github.com/chiahsien/CHTCollectionViewWaterfallLayout.git", :commit => "22a65ac7c4573998c73b298fac9e2ecd2151262b" }
  s.platform     = :ios, '6.0'
  s.source_files = '*.{h,m}'
  s.requires_arc = true
end

(note that I stated iOS 6.0 as minimum required, because with iOS 5.0 the code needs to be modified, which is not handy with Podspecs)

I could add the Podspec myself, but I think it is nicer if the maintainer of a project manages the Podspec.

Construct Grid on the Fly?

I wanted to start a discussion on whether it would be possible to construct the layout on the fly, rather than all at once in prepareLayout.

The reason for this would be for very large data sets. There are times when I display nearly 50,000 cells in a collectionView and it takes a noticeable amount of time to do the height calculations 'heightForItemAtIndexPath.

Instead, would it be possible to 'lazy load' the cell layoutAttributes as you're scrolling?

I'd be happy to take a stab at it, I just wanted to see if there was any concern in doing this.

Thanks!

Large CollectionViewCell's disappearing

When the image in the collection view cell is larger (in height) than the screen bounds, the cell is disappearing. If i slowly scroll down again the cell is reappearing.

I am facing a similar problem like here
http://stackoverflow.com/questions/13770484/large-uicollectionviewcells-disappearing-with-custom-layout

I have tried this way, but no luck
http://juliusparishy.com/puffplus/uicollectionview-large-uicollectionviewcells-disappearing/

Could any one help me.

get you project from pod under ios5

I try to import CHTCollectionViewWaterfallLayout using "pod update ", but I get error:

[!] The platform of the target Pods (iOS 5.0) is not compatible with CHTCollectionViewWaterfallLayout (0.0.1) which has a minimum requirement of iOS 6.0.

How should I do this right?

How to adjust the column spacing

How can i adjust the spacing between two columns so that they look equally spaced between each other and edges of the screen.

Crash through unconditional call of optional delegate method in version 0.3

With version 0.3 a nasty issue has been introduced. In the following method an unconditional call of a delegate method will be done leading to a crash when the delegate doesn't implement this method.

  • (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
    ...
    BOOL hasHeader = [self.delegate collectionView:self.collectionView
    heightForHeaderInLayout:self] > 0;
    ...
    }

Enhancement to delegate method. Asynchronous call perhaps?

Is it possible to make the delegate method heightForItemAtIndexPath an asynchronous call?

Reason for that, if I try to load images (e.g. count=20) into the collectionView from the network/internet, then the prepareLayout will need to loop and wait until all images height is calculated (over the network), then only can it display the collectionview.

Any other alternative?

Utilize iOS 8 self-sizing cells to find out cell dimensions

iOS 8 provides a new self-sizing API for CollectionView and CollectionViewCells. It lets cells determine their own height, based on the content that they're about to load.

This dance involves various methods like

  • preferredLayoutAttributesFittingAttributes: (on the cell)
  • shouldLayoutAttributesFittingAttributes: (on the layout)
  • invalidationContextForPreferredLayoutAttributes:withOriginalAttributes: (on the layout)

The waterfall layout could make use of this dance and harness the self-sizing height measurement, whilst demanding that width be fixed.

Blurry text

I got some blurry text in my cell with UICollectionViewWaterfallLayout.

The problem comes from "- (void)prepareLayout"
When the cell height or width are odd numbers, the frame of the cell will be set to something that is not integers, which causes the blurry text.

Printing description of itemCenter:
(CGPoint) itemCenter = (x=163, y=69)
Printing description of attributes:
<UICollectionViewLayoutAttributes: 0x8911b90> index path: (<NSIndexPath 0xf80e420> 2 indexes [0, 1]); frame = (115.5 6.5; 95 125);

Not a big problem though, but if you round the frame numbers to some integers will make your awesome project easier to use.

Allow to have more than 1 section

Is this a strict limitation to have only 1 section and it's not possible to handle multi-sectioned content with decorations? Or you just didn't look to have more sections?

Not iOS 5 compatible

It's not possible to use it on iOS5. Several points:

  • UICollectionViewDelegate and UICollectionViewLayout do not exist on iOS5
  • When used with PSTCollectionView on iOS5 it raises an exception when PSTCollectionView tries to put itself in collectionView property of the layout.

How to run it in 'xib' but no storyBoard pattern

It no issue run in storyBoard pattern, but I just use 'xib' and xcode log this:2013-07-14 10:10:47.591 testCollection[13852:907] *** -[__NSPlaceholderArray initWithCapacity:]: capacity (4294967295) is ridiculous; correcting, but this is a performance penalty
so how to fix it?please show it to me. Thank you.

Demo in Swift

im new in ios8 and i cant understand your objective-c demo, can you post a Swift demo?

thanks

Item size will animate from small size to big size when CollectionView is created

When my collectionView is created, item's size will animate from custom size to real size (200,50) --- > (200, 100), because the item's size is dynamic.
And also the CHTCollectionViewWaterfallLayout header's subview will animate from small size to the real size ,
but when I load more data , there is no animition.
Why does this happen? How to avoid the cell's and the header's animation when the CollectionView is created?

BTW , only in iOS7+ ,iOS6 works fine.

Crash on data reload with 0 items and sections

First off, great work on the layout. I use the layout for a couple sections with three or four items each. Each section has a header and the items are populated by data retrieved from a network call. I have a method that removes all objects from the data source and sets everything back to zero. For example, 0 sections, with 0 items. Essentially an empty array. The method looks a bit like this:

- (IBAction)resetButtonTapped:(id)sender
{
    [self.dataSource removeAllObjects];
    [self.collectionView reloadData];
}

Whenever I reset everything back to zero, and call reloadData, the following exception is thrown:

*** Assertion failure in -[UICollectionViewData layoutAttributesForSupplementaryElementOfKind:atIndexPath:], /SourceCache/UIKit_Sim/UIKit-3318/UICollectionViewData.m:853
2014-10-19 19:18:22.554 Hord[31192:4215382] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for layout attributes for supplementary view CHTCollectionElementKindSectionHeader in section 0 when there are only 0 sections in the collection view'

A similar issue was reported on another custom UICollectionViewLayout here. However, the other layout appears to have some sort of cache invalidation logic built in.

It looks like the layout object is still trying to return attributes for a header that no longer exists. Any advice you have on resolving this issue is much appreciated. Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.