3

I want to change my collection view layout after rotation in order to change the cell size. In the simulator works great. On iPhone 6 doesn't.

Code is as follows:

-(void)viewDidLoad {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
        [_collectionView registerClass:[TLListCell class] forCellWithReuseIdentifier:kTLAsyncListCell];
        _collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        _collectionView.contentInset = UIEdgeInsetsMake(LIST_GAP, LIST_GAP, LIST_GAP, LIST_GAP);
        _collectionView.backgroundColor = [UIColor clearColor];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        UIRefreshControl *refreshControl = [self reportRefreshControl];
        [_collectionView addSubview:refreshControl];
       [self.view addSubview:_collectionView];
}

-(void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.itemSize = CGSizeMake(20, 20);
    [self.collectionView setCollectionViewLayout:layout animated:YES completion:nil];
    // collection view doesn't respect this layout
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    // not called after changing the layout!!!
}
Avner Barr
  • 13,049
  • 14
  • 82
  • 152
  • I'm currently experiencing a similar issue. My question is http://stackoverflow.com/questions/32127890/settings-uicollectionviewflowlayouts-properties-not-working-when-using-auto-lay. Did you find a fix for this? Your help would be very appreciated :) – s1m0n Aug 21 '15 at 18:43

0 Answers0