0

I have a UINavigationController to control two ViewControllers,VC1 and VC2.

The pic shows is VC2. And there has a UICollectionView as a VC2.view's subview,also there has a UICollectionCell embed in UICollectionView ,as you can see below.

But When I push from VC1 to VC2 ,the UICollectionCell's frame is not correct. The code I write is :

   //VC2.m
   UICollectionViewFlowLayout *l = [[UICollectionViewFlowLayout alloc]init];
   l.itemSize = CGSizeMake(self.bounds.size.width, self.bounds.size.height);
   l.minimumLineSpacing = 6.0f;
   l.sectionInset = UIEdgeInsetsMake(0, 0, 0, 6.0);
   l.scrollDirection = UICollectionViewScrollDirectionHorizontal;
   UICollectionView *parallaxCollection = [[UICollectionView alloc]initWithFrame:frame collectionViewLayout:l];
   [parallaxCollection registerClass:[CollectionCell class] forCellWithReuseIdentifier:@"CollectionCell"];
   [self addSubview:parallaxCollection];

And what I get the frame of cell is (0,-32,320,568) in the initWithFrame:(CGRect)frame:

//CollectionCell.m
-(id)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];

    }
    return self;
}

What's wrong with me?

KittenYang
  • 11
  • 3

2 Answers2

0

Try resize your subviews after init it. Developer library says:

layoutSubviews - Implement this method if you need more precise control over the layout of your subviews than either the constraint or autoresizing behaviors provide.

use

-(void)layoutSubviews
Gürhan KODALAK
  • 570
  • 7
  • 20
0

I fix it ,just add this code in VC2:

self.automaticallyAdjustsScrollViewInsets = NO;

Cause the UICollectionViewCell has a scroll view as the subview.

KittenYang
  • 11
  • 3