Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behaviour when inserting new cells. #30

Closed
markst opened this issue Oct 8, 2014 · 9 comments
Closed

Unexpected behaviour when inserting new cells. #30

markst opened this issue Oct 8, 2014 · 9 comments

Comments

@markst
Copy link

markst commented Oct 8, 2014

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.

@jamztang
Copy link
Collaborator

Can you provide more information or a sample project so we can take a look?

@markst
Copy link
Author

markst commented Nov 11, 2014

http://d.pr/v/10Icq

@jamztang
Copy link
Collaborator

Which version are you using and is the bouncing the section header or the stickyheader?

@markst
Copy link
Author

markst commented Nov 12, 2014

Using version 0.2.3

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
           viewForSupplementaryElementOfKind:(NSString *)kind
                                 atIndexPath:(NSIndexPath *)indexPath
{
    if ([kind isEqualToString:CSStickyHeaderParallaxHeader]) {
        if (self.mapHeader == nil) {
            _mapHeader = [collectionView
                          dequeueReusableSupplementaryViewOfKind:CSStickyHeaderParallaxHeader
                          withReuseIdentifier:@"MapHeader"
                          forIndexPath:indexPath];

        }
        return self.mapHeader;
    } else if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {

        //TODO: Move this to an appearance class.
        [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont proximaNovaRegularFontWithSize:15.0]];

        UICollectionReusableView * cell = [collectionView
                                           dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
                                           withReuseIdentifier:@"SearchHeader"
                                           forIndexPath:indexPath];
        UISearchBar * searchBar = (UISearchBar *)[cell viewWithTag:200];
        [searchBar setDelegate:self];
        [searchBar setPlaceholder:@"Search by Postcode or Suburb"];
        [searchBar setTintColor:[UIColor tn_charcoal]];
        [searchBar setBarTintColor:[UIColor whiteColor]];
        [searchBar setBackgroundColor:[UIColor whiteColor]];
        [searchBar setBackgroundImage:[UIImage new]];
        [searchBar setShowsCancelButton:YES];
        [searchBar setScopeBarButtonTitleTextAttributes:@{NSFontAttributeName:[UIFont proximaNovaBoldFontWithSize:15.0]}
                                               forState:UIControlStateNormal];
        return cell;
    }
    return nil;
}

@gjeck
Copy link

gjeck commented Nov 20, 2014

I have a similar issue on the same version. The stickyHeader and regular sectionHeader animate oddly when reloading sections. It seems that the stickyheader content is being animated when we expect it to remain static.

let indexSet = NSIndexSet(indexesInRange: NSMakeRange(0, self.collectionView.numberOfSections()))
collectionView.reloadSections(indexSet)

@jamztang
Copy link
Collaborator

I notice the initial attributes were not modified to reflect the change. I made a small patch and pushed to the demo project, let me know if that works for you guys!

@nferruzzi
Copy link

Same problem here and the small patch doesn't fix it for me. On my side the problem is triggered when I perform insertItemsAtIndexPath inside a performBatchUpdates; with a simple reloadData the sticky header works just fine.

@nbwar
Copy link

nbwar commented Dec 31, 2014

@nferruzzi Place your performBatchUpdates in a UIView.animationWithDuration block for example

UIView.animateWithDuration(0, animations: {
    self.collectionView.performBatchUpdates({
        var indexPaths:[NSIndexPath] = []

         for var i = oldSize; i < self.data.count; i++ {
            indexPaths.append(NSIndexPath(forItem: i, inSection: 0))
          }
          self.collectionView.insertItemsAtIndexPaths(indexPaths)
      }, completion: nil)
})

@jamztang
Copy link
Collaborator

0.2.8 has some updates on better handing animation, please feel free to reopen if still have issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants