Как увеличить / уменьшить только одну отдельную ячейку табличного представления, а не всю таблицу? - PullRequest
3 голосов
/ 22 марта 2012

Я хочу увеличить / уменьшить только одну конкретную строку / ячейку табличного представления, а не всю таблицу. Я использовал жест щипка, но он не работает в ячейке таблицы, он работает во всей таблице.

Мне нужно увеличивать одну ячейку за раз, а когда я хочу увеличить 2-ю ячейку, то автоматически изменяем размер?

Пожалуйста, помогите мне.

Заранее спасибо.

Ответы [ 4 ]

4 голосов
/ 22 марта 2012

Вы можете попробовать следующий код:

    // For Zoom  in 
    CGAffineTransform trans = CGAffineTransformScale(cell.contentView.transform, 100, 100);
    view.transform = trans;

   // For Zoom Out
   CGAffineTransform trans = CGAffineTransformScale(cell.contentView.transform, 0.01, 0.01);
   view.transform = trans;

Вы можете использовать это для didSelectRowAtIndexPath метода.

Под didSelectRowAtIndexPath: введите следующий код, чтобы получить выбранный cell

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

Теперь у вас есть cell

0 голосов
/ 24 сентября 2017

Вы можете сделать это так:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [self itemSelected:indexPath];
}

- (void)itemSelected:(NSIndexPath *)indexPath {

    [UIView animateWithDuration:0.3 animations:^{
        [self animate:indexPath highlighted:YES];
    } completion:^(BOOL finished) {
        [self animate:indexPath highlighted:NO];
    }];
}

- (void)animate:(NSIndexPath *)indexPath highlighted:(BOOL)highlighted {
    SoundEffectsCell *cell = (SoundEffectsCell *)[_collectionView cellForItemAtIndexPath:indexPath];

    float scale = highlighted ? 0.9 : 1.0;

    [UIView transitionWithView:_collectionView duration:0.1 options:UIViewAnimationOptionTransitionNone animations:^{
        cell.transform = CGAffineTransformMakeScale(scale, scale);
    } completion:nil];
}

Пожалуйста, замените CollectionViewCell на ваш.Я реализовал это с UICollectionView, но то же самое и с UITableView.

0 голосов
/ 30 июля 2016

взять переменную

NSInteger selectedindex

Теперь введите эту вещь в

 - (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   //whatever your code write here

   if (selectedindex == indexPath.row) {
         [self animateZoomforCell:cell];
   }else
   {
         [self animateZoomforCellremove:cell];
   } 
   return cell;
 }

 - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //whatever your code write here

  selectedindex =indexPath.row; 
    [self.tableView reloadData];
 }

Вы можете использовать этот метод для увеличения / уменьшения ячейки

  -(void)animateZoomforCell:(UITableViewCell*)zoomCell {
       [UIView animateWithDuration:0.2 delay:0  options:UIViewAnimationOptionCurveEaseOut
          animations:^{

       zoomCell.transform = CGAffineTransformMakeScale(1.6,1.6);
         } 
         completion:^(BOOL finished){
         }];
        }

   -(void)animateZoomforCellremove:(UITableViewCell*)zoomCell {
       [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{

        zoomCell.transform = CGAffineTransformMakeScale(1.0,1.0);
      }   
         completion:^(BOOL finished){
      }]; 
      }
0 голосов
/ 22 марта 2012

Вы пытались написать код ответа @Devang внутри

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Надеюсь, это поможет.

...