Coder Social home page Coder Social logo

csstickyheaderflowlayout / csstickyheaderflowlayout Goto Github PK

View Code? Open in Web Editor NEW
5.0K 5.0K 609.0 1021 KB

UICollectionView replacement of UITableView. Do even more like Parallax Header, Sticky Section Header. Made for iOS 7.

Home Page: https://medium.com/ios-apprentice/43e943e6627

License: MIT License

Objective-C 78.19% Ruby 8.18% Swift 13.64%

csstickyheaderflowlayout's Introduction

CSStickyHeaderFlowLayout

Contributors

For anyone who'd like to be a contributor to the repository, please read the Contribution Guideline


Parallax, Sticky Headers, Growing image heading, done right in one UICollectionViewLayout.

Installation

Version Platform

Cocoapods

CSStickyHeaderFlowLayout is available through CocoaPods, to install it simply add the following line to your Podfile:

pod "CSStickyHeaderFlowLayout"

Carthage

CSStickyHeaderFlowLayout is also available with Carthage. Add github "CSStickyHeaderFlowLayout/CSStickyHeaderFlowLayout" to your Cartfile

Alternatively, you can just drag the files from CSStickyHeaderFlowLayout / Classes into your own project.

Usage (Swift/Code)

Documentation is coming soon. For now please open CSStickyHeaderFlowLayout.xcworkspace > SwiftDemo target.

Usage (CocoaPods/Objective-C/Storyboard)

To run the example project; clone the repo, and run pod install from the Project directory first.

1. Setting up the Sticky Section Header

Configure your collection view to use CSStickyHeaderFlowLayout. Here's an example on how you to do it in Storyboard.

Now all your section headers will get the sticky effect like table view. You can disable it with one line of code.

@property (nonatomic) BOOL disableStickyHeaders;

2. Setting up the Collection View Header

We'll be using supplementary views for our parallax header. Here's an example on how use a nib file for that purpose:

Register that nib file to your collection view controller in code:

#import "CSStickyHeaderFlowLayout.h"

- (void)viewDidLoad {

    [super viewDidLoad];

    // Locate your layout
    CSStickyHeaderFlowLayout *layout = (id)self.collectionViewLayout;
    if ([layout isKindOfClass:[CSStickyHeaderFlowLayout class]]) {
        layout.parallaxHeaderReferenceSize = CGSizeMake(320, 200);
    }

    // Locate the nib and register it to your collection view
    UINib *headerNib = [UINib nibWithNibName:@"CSGrowHeader" bundle:nil];
    [self.collectionView registerNib:headerNib
          forSupplementaryViewOfKind:CSStickyHeaderParallaxHeader
                 withReuseIdentifier:@"header"];

}

Implement -[UICollectionViewDataSource collectionView:viewForSupplementaryElementOfKind:atIndexPath:]

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {

    // Check the kind if it's CSStickyHeaderParallaxHeader
    if ([kind isEqualToString:CSStickyHeaderParallaxHeader]) {

        UICollectionReusableView *cell = [collectionView dequeueReusableSupplementaryViewOfKind:kind
                                                                            withReuseIdentifier:@"header"
                                                                                   forIndexPath:indexPath];

        return cell;

    } else if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        // Your code to configure your section header...
    } else {
        // other custom supplementary views
    }
    return nil;
}

That's it. You'll be able to get the header you wanted using the best practice.

Configuring other effects are really just the way how you setup the header cell, by combining different settings in the minimal exposed properties in CSStickyHeaderFlowLayout.h

@property (nonatomic) CGSize parallaxHeaderReferenceSize;
@property (nonatomic) CGSize parallaxHeaderMinimumReferenceSize;
@property (nonatomic) BOOL disableStickyHeaders;

Run the project examples and it'll shows you exactly how you achieve different effects.

Updates

  • 0.2.12: Add Swift 5 Demo

  • 0.2.11: Add support for carthage.

  • 0.2.10: Fixed issue because attributes were not copied and datasource might have been niled

  • 0.2.9: Remove Supplementry Header Layout Attribute to prevent crash when returning nil and while is CGSizeZero

  • 0.2.8: Fixed a visual issue when animating contentInsets #85 and crash when dragging cells #69

  • 0.2.7: Fixed scroll indicator covered by cell

  • 0.2.6: Fixing that section header being covered by cell after perform batch update

  • 0.2.5: Fixing a crash when quickly popping back to a view controller using the parallax header

  • 0.2.4: Possibly fix for a crash when parallaxHeaderReferenceSize is changed

  • 0.2.3: Enabled iPhone 6 screen sizes, reverted a patch and fixed a visual bug and content tapping bug.

  • 0.2.2: Fix 1px header and zIndex problem, thanks @m1entus and @Xyand

  • 0.2.1: Fix crash on reloadData in collection view when header is offscreen, thanks @jessesquires

  • 0.2: Added custom UICollectionViewLayoutAttributes to support more advanced example (Spotify App)

  • 0.1.1: Minor fixes for default number of sections, thanks @miwillhite

  • 0.1: Initial Release

Who's using it?

We've a wiki page for that, feel free to add your projects there!

Requirements

  • Xcode 5
  • iOS 7 (I haven't really test on iOS 6 but it should work if you're using iOS 6 compatible Storyboard)

Author

James Tang, [email protected]

License

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

csstickyheaderflowlayout's People

Contributors

amirehsanijam avatar andreamazz avatar bitdeli-chef avatar chrene avatar dannyshmueli avatar i3th avatar jamztang avatar jessesquires avatar jianing93 avatar jorjuela33 avatar kaandedeoglu avatar luzo avatar marciomeschini avatar michalz-railwaymen avatar miwillhite avatar skywinder avatar starwars avatar xyand avatar yimingtang 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

csstickyheaderflowlayout's Issues

layoutAttributesForSupplementaryViewOfKind:atIndexPath: doesn't take into account parallaxHeaderReferenceSize

When using:

UICollectionViewLayoutAttributes *attributes = [super layoutAttributesForSupplementaryViewOfKind:kind atIndexPath:indexPath];

It doesn't take into account parallax header size so the returned frame is wrong.

When using:

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect

It seems to handle it the right way:

    CGRect frame = attributes.frame;
    frame.origin.y += self.parallaxHeaderReferenceSize.height;
    attributes.frame = frame;

Support device rotation

@jamztang This project is awesome! Saved me so much time. Thank you! One quick question, I don't think the demo project supports device rotation, see screenshot below. How can the header support rotation?

image

MapView inside header not working

I have my own collection view controller using the demo's CSParralaxHeader's mapview (added it is a property to the view's header file). The view controller displays the sticky header and the mapview, but it doesn't display any annotation views or more importantly, fire any methods such as changing map type, zooming to region, etc. Not sure if this is an issue within the repository, or just me not setting up right. With that being said, what is the correct way to set up and use a mapview within a collection view header as displayed in one the examples (the one with the car listings).

ParallaxHeader crash if contain a UILabel

When you start scrolling the tableView/collectionView, and the header will disappear, the label will cause the app to crash.

Getting UILabel length, unrecognized selector sent to instance ...

Tried with constraints and visual format constraint. Xcode 6, ios 8.

Flow Layout debug warning

A BIG thank you for the fantastic flow layout solution.

One small issue I have is when the header has been stretched and is allowed to bounce back to its original height i get...

the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values.

Its not so much a bug but more of a frustration as it spams the console for as many frames it takes for the collection view to come to rest.

Any ideas on how to fix this?

support 6.0

thank you this project at frist๏ผ Could you let it supports 6.0๏ผŸ

Setting contentInset causes header image to "jump" from bottom to top

I'm building an application which has a UITextField outside the collection view. I'm trying to animate setting the bottom inset to cover up the space occupied by the keyboard. Setting contentInset in the animation block causes the header image jump bottom to top sometimes.

Here's the video demonstrating the problem.
http://cl.ly/0w3x1X3f0p0v

The following is the code used for setting the insets. The UITextField is independent of the Collection View and has a bottom constraint with the bottom layout guide.

    func keyboardWillShow(notification: NSNotification){
        let info: NSDictionary = notification.userInfo!
        let keyboardFrame = (info[UIKeyboardFrameEndUserInfoKey] as NSValue).CGRectValue()

        // Take the comment box up
        bottomHeightConstraint.constant = keyboardFrame.height
        self.view.setNeedsUpdateConstraints()

        UIView.animateWithDuration(1, delay: 0, options: UIViewAnimationOptions.BeginFromCurrentState, animations: { () -> Void in
            self.view.layoutIfNeeded()
            // Inset from bottom equal to the height of keyboard
            self.collectionView.contentInset = UIEdgeInsetsMake(0, 0, keyboardFrame.height, 0)
            }, completion: nil)
    }

    func keyboardWillHide(notification: NSNotification){
        // Bring the comment box down
        bottomHeightConstraint.constant = 0
        self.view.setNeedsUpdateConstraints()

        UIView.animateWithDuration(1, delay: 0, options: UIViewAnimationOptions.BeginFromCurrentState, animations: { () -> Void in
            self.view.layoutIfNeeded()
            self.collectionView.contentInset = UIEdgeInsetsZero
            }, completion: nil)
    }

I'm not aware of UICollectionView internals and the layouts but I'm guessing the problem is in the layout's header rendering code. Is there any solution/better way to solve this? Thanks in advance!

Crash on iOS8 with auto sizing cells enabled.

When auto sizing cells is enabled via setting estimated size
layout.estimatedItemSize = CGSizeMake(self.view.bounds.size.width, 80);
there is a crash in - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect method.

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    // The rect should compensate the header size
    CGRect adjustedRect = rect;
    adjustedRect.origin.y -= self.parallaxHeaderReferenceSize.height;

    NSMutableArray *allItems = [[super layoutAttributesForElementsInRect:adjustedRect] mutableCopy]; <-crash here 
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
...
}

Didn't found remedy for it yet. Auto sizing is important feature, takes a lot of pain away. Would be cool if this was solved somehow.

It doesn't seem to work with Swift

I'm trying to set it up from a project using Swift. It builds and it's set up as it should but the parallax effect isn't working. It calls the Objective-C code correctly but with no effect on my header. Have you tried using it with Swift? Thanks

Autolayout Error

I get the following error when running the code on an iPhone 6...

Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7fd31b68a0a0 V:[UIView:0x7fd31b686bb0(366)]>",
"<NSLayoutConstraint:0x7fd31b68a5d0 V:[UIView:0x7fd31b686bb0]-(0)-| (Names: '|':UIView:0x7fd31b686ae0 )>",
"<NSLayoutConstraint:0x7fd31b474dc0 V:|-(0)-[UIView:0x7fd31b686ae0] (Names: '|':UIView:0x7fd31b6807c0 )>",
"<NSLayoutConstraint:0x7fd31b430240 V:[UIView:0x7fd31b686ae0]-(0)-| (Names: '|':UIView:0x7fd31b6807c0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7fd31b7e1fd0 h=--& v=--& V:[UIView:0x7fd31b6807c0(407)]>",
"<NSLayoutConstraint:0x7fd31b68a750 V:|-(>=48)-[UIView:0x7fd31b686bb0](Names: '|':UIView:0x7fd31b686ae0)>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fd31b68a0a0 V:[UIView:0x7fd31b686bb0(366)]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

Support for landscape mode

Is there any way to add support for landscape mode as well in this library. Or Could you please suggest a similar implementation supporting landscape mode too.

swift applyLayoutAttributes inconsistent

The sample you provided using "CSStickyHeaderFlowLayoutAttributes" as parameter type but when i used in swift it came with "UICollectionViewLayoutAttributes" base class

your sample

- (void)applyLayoutAttributes:(CSStickyHeaderFlowLayoutAttributes *)layoutAttributes {

swift

override func applyLayoutAttributes(layoutAttributes: UICollectionViewLayoutAttributes!) {

i created another variable and used this way

let attr = layoutAttributes as! CSStickyHeaderFlowLayoutAttributes

Section Header can't receive touches

I have an outlet to a UISwitch in a UICollectionViewCell that is returned as a section header inside of:

func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView

I am unable to touch the switch, or any interactive controls, inside of the section header. However, controls inside the non-header cells are fine.

How to collapse CSAlwaysOnTopHeader

Congrats on a great library. I'm using it to do something very similar to the spotify example, but I want the header to be initially collapsed (only the spotify button displayed, hidden picture, etc), how can I achieve this? I've tried setting the frame programatically upon initialisation but this causes some odd flickering on the first expansion, probably due to the layout constraints being incorrect. Thx in advance.

Crash on reloadData in collection view when header is offscreen

Hello again @jamztang - found some issues with reloading data on the collection view.

The CSStickyHeaderFlowLayout was calling its base class UICollectionViewLayout layoutAttributesForSupplementaryViewOfKind: method to get layout attributes. That base class knows nothing about the CSStickyHeaderParallaxHeader kind of supplementary view, and was returning nil.

Fix:

- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewLayoutAttributes *attributes = [super layoutAttributesForSupplementaryViewOfKind:kind atIndexPath:indexPath];
    if (!attributes && [kind isEqualToString:CSStickyHeaderParallaxHeader]) {
        attributes = [CSStickyHeaderFlowLayoutAttributes layoutAttributesForSupplementaryViewOfKind:kind withIndexPath:indexPath];
    }
    return attributes;
}

iPhone 6 & Plus Sizes

Hello,

I'm using CSStickyHeaderFlowLayout, and now testing on iPhone 6 and iPhone 6 Plus I noticed that the size of the section and the items are weird. I'm using StoryBoards, see both images on iPhone 5 and 6 Plus

img_0488
ios simulator screen shot oct 13 2014 4 10 39 pm

NSInternalInconsistencyException when scrolling to the bottom

Hi James.
I'm struggling with an issue... I'm using your library in a collection view, and I noticed that sometimes the system raises an NSInternalInconsistencyException when scrolling to the bottom. It looks like it's correlated to the amount of cells displayed. I was able to recreate the issue in your sample, by providing only 2 sections, the first one with one item, the second one with 4. (You can find the sample in my fork).
Here's the catch: it only happens when I compile with Xcode 5.1 on an iOS8 device (beta5). If I compile with Xcode6 everything goes smoothly. Given the circumstances it might not even be worth spending too much time fixing this, as it's probably a bug introduced in the latest beta, but if someone with the current iOS8 beta downloads an app from the store with this component, it might crash.
Here's the full stack trace:

2014-08-07 16:03:14.718 CSStickyHeaderFlowLayoutDemo[1538:270805] 
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
 reason: 'layout attributes for supplementary item at index path (<NSIndexPath: 0x1a07c410> {length = 2, path = 1 - 0}) 
changed from <CSStickyHeaderFlowLayoutAttributes: 0x16d4a050> index path: (<NSIndexPath: 0x1a08e4c0> {length = 2, path = 1 - 0}); 
element kind: (UICollectionElementKindSectionHeader); 
frame = (0 330; 320 50); 
zIndex = 1024;  
to <CSStickyHeaderFlowLayoutAttributes: 0x1a097e80> index path: (<NSIndexPath: 0x1a07c410> {length = 2, path = 1 - 0}); 
element kind: (UICollectionElementKindSectionHeader); 
frame = (0 278.5; 320 50); 
zIndex = 1024;  without invalidating the layout'

anyway, thanks for your great work. ๐Ÿ‘
Cheers.

Creating constraint programmatically for the Parallax Header

I am trying to create Visual Format constraint for the parallax header. I am following your example from your github.

But still have problems. If I create the constraints in the collectionView:viewForSupplementaryElementOfKind:atIndexPat the OS complain that the headerview does not have a superview. And thats true, since it havent returned to collectionView.
And if I add it to the viewDidLoad it will not show, or get the same error then above.

How to create "Spotify" example programmatically?

I'm having problems creating the "Spotify" example programmatically. The header does not scroll away and I can't get the button (a UISegmentedControl, in my case) to stick at the top.

Could you please post an example of how to create the header and set it up programmatically, without IB and NIBs?

Crash on iOS 8.1

Hi jamztang,

Your CSStickyHeaderFlowLayout is good but it crash on iOS 8.1

@implementation CSStickyHeaderFlowLayout
...

  • (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
    {
    // The rect should compensate the header size
    CGRect adjustedRect = rect;
    adjustedRect.origin.y -= self.parallaxHeaderReferenceSize.height;

=>> NSMutableArray *allItems = [[super layoutAttributesForElementsInRect:adjustedRect] mutableCopy]; // Crash is here

2014-11-03 10:54:21.844 AlloCine[313:44884] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil'

Can you check if you have this crash too please ?

Thanks for your help.

Ouatelse !

SHUFFLE PLAY button is not tappable sometimes

  1. Run CSStickyHeaderFlowLayoutDemo
  2. Select tab "Always On Top"
  3. Tap the green button "SHUFFLE PLAY" - it tapped well
  4. Scroll the list until "Song 18" is visible
  5. Tap the green button "SHUFFLE PLAY" - sometimes it ignores taps.

Expected result: the green button "SHUFFLE PLAY" should be tappable well always.

Reproduced on a device and the simulator, checked with iOS 7.1 and iOS 8.

layoutAttributesForSupplementaryViewOfKind always returns nil

First of all I wanted to thank you for your great work.

I've been trying to add an initial top margin to the header image in some cases so that when the user starts scrolling the header the margin starts being phased out before the header image.

I replaced

CGFloat y = CGRectGetMaxY(currentBounds) - currentBounds.size.height + self.collectionView.contentInset.top;

with

CGFloat y = CGRectGetMaxY(currentBounds) - currentBounds.size.height + self.collectionView.contentInset.top + self.headerMargin;

and even

if (!attributes && [kind isEqualToString:CSStickyHeaderParallaxHeader]) 
{
    attributes = [CSStickyHeaderFlowLayoutAttributes layoutAttributesForSupplementaryViewOfKind:kind withIndexPath:indexPath];
}

with

if (!attributes && [kind isEqualToString:CSStickyHeaderParallaxHeader]) 
{
    attributes = [CSStickyHeaderFlowLayoutAttributes layoutAttributesForSupplementaryViewOfKind:kind withIndexPath:indexPath];

    CGRect frame = attributes.frame;
    frame.origin.y += self.parallaxHeaderReferenceSize.height + self.headerMargin;
    attributes.frame = frame;
}

but neither approaches seems to do the trick, why? because attributes always equals to nil.

appreciate your support :)

Demo Fails

$ cd Project/
$ pod install
[!] Unable to satisfy the following requirements:
- `CSStickyHeaderFlowLayout (from `../CSStickyHeaderFlowLayout.podspec`)` required by `Podfile`

ContentOffset on bottom causes flickering to occur when scrolling down

If you set the contentOffset's bottom of the collectionView to 200+, you should see it. When you scroll down(as in, swiping up with your thumb to get to the bottom of the feed), the parallax header at top disappears for a second then reappears. This is obvious when you have a lot of velocity going into the bounce.

Where does it go during this?

I've been able to capture the moments in which it disappears (I set a breakpoint when the difference between pastY and currentY are > 40), and have played with quite a few variables, but can't get it. Can you please have a look when you get the chance? If it helps, I have:

  • Parallax header (min: 80px)
  • Sticky header (100px)
  • Rows of 120px

The parallax header disappears momentarily and I see the rows and header -- sometimes even the back of the collectionview. There's times when you can stop directly on it just manually scrolling. If the update finishes and Z isn't 2000 (I think), then it's not to be found.

Where does the "header" reuseIdentifier come from?

In the example code I noticed this line:

[self.collectionView registerNib:self.headerNib forSupplementaryViewOfKind:CSStickyHeaderParallaxHeader withReuseIdentifier:@"header"];

But I can't find where the "header" reuse identifier key is specified. I only find the "sectionHeader" reuse identifier in the storyboard. Does this reuse identifier get created internally by CSSStickyHeaderFlowLayout?

Permit cell height to be zero

Currently enforces 1 as a minimum. Zero would permit a header that is entirely recessed.

CGFloat height = MAX(0, -y + maxY);

Sticky Header programmatically

Thanks for creating such a easy to use library. I can successfully implement the "Always On Top" sample on my app using IB. However, when I try to do everything in code, I am a little bit stuck (which means that I am not fully understanding the mechanism).

Anyway, can you please explain how the "Shuffle" button (in the Always On Top sample) get scrolled with the rest of the collection while the parallax header remains there? The header and the shuffle button belong to the same XIB and Cell class.

I created a GroupHeaderCell to represent the parallax header (see below). But when I scroll, the header remains there. I would want the tabBar to be scrolled up and be sticky at the top.

Any idea would help.

Thanks!

  class GroupHeaderCell: UICollectionViewCell, UITabBarDelegate {

   var backgroundImage: UIImageView?

   init(frame: CGRect) {
    NSLog("GroupHeaderCell initWithFrame \(frame.origin.x) x \(frame.origin.y) @ (\(frame.width), \(frame.height))")
    super.init(frame: frame)

    let tabBar = UITabBar(frame: CGRectMake(0, 200, frame.width, 80))
    tabBar.delegate = self

    let tabBarItem = UITabBarItem(tabBarSystemItem: UITabBarSystemItem.Favorites, tag: 1)
    tabBar.items = [ tabBarItem ]

    self.backgroundImage = UIImageView(frame:CGRectMake(0, 0, frame.width, 200))
    self.contentView.addSubview(self.backgroundImage)
    self.contentView.addSubview(tabBar)
    self.backgroundColor = UIColor.redColor()
  }

"Snapshotting a view that has not been rendered results in an empty snapshot."

First of all, great work! This works really well in most cases and is incredibly easy to use.

I currently have a collection view with multiple sections. Each section's header has a button that allows the user to expand or collapse the contents of the section. When the section's contents are expanded and the header is "sticking" to the top of the collection view, if I collapse that section's content (using "reloadSections" if that's important), I get the following error/warning, "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."

It doesn't crash the app, but I like to do things right so I'd like to get rid of the error/warning. Any ideas? It seems like it may have something to do with the header abruptly becoming "unstuck."

P.S.

If it's relevant, I display/hide the cells using the "numberOfItemsInSection" delegate method.

P.P.S.

I don't get the warning/error if I use "reloadData."

EXC_BAD_ACCESS on [super collectionViewContentSize];

I have spotted this issue in iPad Mini with iOS 8.1.1 and I can repeat them.

I have a storyboard with navigation controller and two view controllers.
I use CSStickyHeaderFlowLayout in these two view controllers.

When I segued to second view controller from the main view controller, and at this moment I quickly tapped on the back button. Voila... EXC_BAD_ACCESS.

screen shot 2014-12-11 at 6 03 41 pm

By the way I used [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:...]]; in sectioned collectionView.

Solution?

Autolayout for header?

Anyone has hints on how to implement autolayout for the header size so it'll play nice for different orientations nicely?

Unexpected behaviour when inserting new cells.

I have my UICollectionView backed by a NSFetchedResultsController to insert/update cells.

My cells get inserted as the user scrolls. What seems to happen is the sticky headers scroll down & then return once the bounce deceleration animation is complete.

I think a solution would be to only insert cells once animation deceleration is complete.

NSInternalInconsistencyException crash in logs

Fatal Exception: NSInternalInconsistencyException layout attributes for supplementary item at index path (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}) changed from <CSStickyHeaderFlowLayoutAttributes: 0x14e6a1ad0> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); element kind: (CSStickyHeaderParallexHeader); frame = (0 0; 0 0); to <CSStickyHeaderFlowLayoutAttributes: 0x151865db0> index path: (<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}); element kind: (CSStickyHeaderParallexHeader); frame = (0 -1.33333; 414 311.833); without invalidating the layout

Getting a lot of crashes like this with stacktrace:

4 UIKit 0x0000000186c3a87c __45-[UICollectionViewData validateLayoutInRect:]_block_invoke + 1004

5 UIKit 0x0000000186c39f74 -[UICollectionViewData validateLayoutInRect:] + 1492

6 UIKit 0x0000000186c397a0 -[UICollectionView layoutSubviews] + 160

Layout assertion failure

Project setup as specified in README.

 *** Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:]
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath (CSStickyHeaderParallexHeader,<NSIndexPath: 0x15eba8e0> {length = 2, path = 0 - 0}) was not retrieved by calling -dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath: or is nil ((null))'
*** First throw call stack:

Layout not working on iOS7.1

Hi!

It seems to me, that the layout does not work well on iOS7. I just downloaded the code and build it with XCode 6.0.1 to the iOS Simulator iPhone 5s -iOS 7.1 (on OS X 10.9.5).
The header is always fix on the top, no growing, no parallax effect. I could not test it on the real device only on simulator. On iOS8 the layout is working well.

Could you reproduce it?

pod install fails

~/W/O/C/Project (master) $ pod install
Analyzing dependencies
Fetching podspec for `CSStickyHeaderFlowLayout` from `../CSStickyHeaderFlowLayout.podspec`
[!] Unable to satisfy the following requirements:

- `CSStickyHeaderFlowLayout (from `../CSStickyHeaderFlowLayout.podspec`)` required by `Podfile`
- `CSStickyHeaderFlowLayout (= 0.2)` required by `Podfile.lock`

Version:

~/W/O/C/Project (master) $ pod --version
0.35.0.rc2

Removing cells changes the frame of the header.

Recreating the Spotify parallax.

I have this issue where upon removing a cell from my collection view, the header's y origin will be offset by the offset of the last cell's view on the screen. For example, my cell's height is 55. If I scroll all the way to the bottom, and the entire last cell is showing, then remove a cell, the header will drop down 55 points. like this.
screen shot 2015-02-21 at 5 56 17 pm

(That black space above the image is the offset, same height as my cells.)

If only like half of the last cell is showing, then the header will drop down only like 22.5. Understand?
If the last cell is not showing at all then everything updates as it should.

Also, once the header is screwed up, as soon as scrollViewDidScroll, the header returns exactly to where it should be and everything works as it should again.

Any idea how I can fix this?

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.