Неправильная компоновка ячеек представления коллекции на iPhone X - PullRequest
0 голосов
/ 09 февраля 2020

У меня есть контроллер представления, содержащий представление коллекции со следующей настройкой:

- (void)viewDidLoad {
    [super viewDidLoad];

    [self createDataSource]; //this one contains 6 UIColor objects used for the collection view cells

    UINib *cellNib = [UINib nibWithNibName:@"CustomCollectionViewCell" bundle:nil];
    [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"customCollectionViewCellIdentifier"];
}

Методы UICollectionViewDataSource выглядят так:

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CustomCollectionViewCell *customCollectionViewCell = (CustomCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"customCollectionViewCellIdentifier" forIndexPath:indexPath];

    UIColor *color = self.dataSource[indexPath.item];
    customCollectionViewCell.childView.backgroundColor = color;

    return customCollectionViewCell;
}

Методы UICollectionViewDelegateFlowLayout выглядят так:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

    CGSize cellSize = CGSizeMake(self.collectionView.frame.size.width / 2, self.collectionView.frame.size.height / 3);

    return cellSize;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {

    return UIEdgeInsetsZero;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {

    return 0;
}

При этом результат на iPhone X не такой, как на iPhone 6S Plus.

iPhone 6S Plus: enter image description here

iPhone X результат: enter image description here

Как можно добиться того же результата на iPhone X?

Спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...