2016-06-09 12 views
1

Ich habe ein Problem mit UICollectionViewCell Design-Layout. Ich brauche Raum mit Animation zu entfernen, während zwischen UICollectionView Handy Scrollen, habe ich einige Delegatmethode von UICollectionView versuchen, wie -UICollectionViewCell Raum mit Animation beim Scrollen entfernen

  • Collection - minimumLineSpacingForSectionAtIndex
  • Collection - minimumInteritemSpacingForSectionAtIndex
  • UIEdgeInsetsMake (0,0,0,0);
  • scrollViewDidEndDragging

aber nicht in der Lage bis zur Marke. hier ist der Code:

- (CGSize)collectionView:(UICollectionView *)collectionView 
       layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
    { 
    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    CGFloat screenWidth = screenRect.size.width; 
    float cellWidth = screenWidth/2.1; //Replace the divisor with the column count requirement. Make sure to have it in float. 
    CGSize size = CGSizeMake(cellWidth, cellWidth); 

    return size; 
} 

    - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section 
{ 
    return 1.0; 
} 

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section 
{ 
    return 1.0; 
} 

// Layout: Set Edges 
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section 
{ 
    return UIEdgeInsetsMake(0,0,0,0); // top, left, bottom, right 
} 

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate 
{ 
    UIEdgeInsetsMake(0,0,0,0); // after scroll cell space not remove. 
} 

enter image description here

+0

einige Code setzen, die Sie verwenden. –

Antwort

0

ich nicht ganz verstanden, was Sie zu tun versuchen, aber wenn Sie wollen Layout Attribute einer Sammlung Ansicht ändern und die Änderung animieren, die beste Weg ruft setLayout:animated:.

So wie dieser -

UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout alloc] init]; 
layout.minimumLineSpacing = 1.0; 
layout.minimumInteritemSpacing = 1.0; 
layout.itemSize = CGSizeMake(cellWidth, cellHeight); 

UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:frame collectionViewLayout:layout] 

Und dann, wenn Sie es ändern möchten, rufen Sie einfach die setLayout:animated: Methode:

UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout alloc] init]; 
initialLayout.minimumLineSpacing = 5.0; 
initialLayout.minimumInteritemSpacing = 7.0; 
layout.itemSize = CGSizeMake(newCellWidth, newCellHeight); 

[collectionView setLayout:layout animated:YES]; 
Verwandte Themen