CollectionView: Как увеличить размер ячейки для ячейки, которая находится в центре вида? - PullRequest
0 голосов
/ 28 января 2019

Я хочу создать дизайн, подобный этому изображению .Это пользовательский интерфейс камеры, в котором пользователь может прокручивать различные маски и применять любую маску во время записи видео.

Я просмотрел множество URL-адресов, таких как:

Swift Как сделатьполучить центральную ячейку в CollectionView и изменить ее размер при прокрутке?

Как увеличить центральное изображение при горизонтальной прокрутке?

Но ни одно из этих решений не сработалодля меня.

Вот мой код:

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

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


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGPoint point = CGPointMake(self.view.frame.size.width/2.0,40);
        if([collectionView indexPathForItemAtPoint:point] != nil)
        {
            NSIndexPath *centerIndex = [collectionView indexPathForItemAtPoint:point];
            if(centerIndex != nil)
            {
                if (indexPath.item == centerIndex.item) {
                    return CGSizeMake(100, 100);
                }
            }
        }
    return CGSizeMake(80, 80);
}

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

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

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    FavImageCollectionViewCell *newCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FavImageCollectionViewCell" forIndexPath:indexPath];
    if (!newCell)
    {
        NSArray *cellArray = [[NSBundle mainBundle] loadNibNamed:@"FavImageCollectionViewCell" owner:self options:nil];
        newCell = [cellArray objectAtIndex:0];
    }

    newCell.contentView.backgroundColor = [UIColor redColor];

    return newCell;
}

Но здесь, в моем коде, приложение падает на

[collectionView indexPathForItemAtPoint: point]

Выдает ошибку вроде:

Завершение приложения из-за необработанного исключения 'NSRangeException', причина: '*** - [__ NSArrayM objectAtIndex:]: индекс 1 за пределами [0 .. 0] '

Буду очень признателен за любые предложения или улучшения моего кода.

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