How can I increase / decrease only one specific cell of the table and not the whole table?

I only want to increase / decrease one specific row / cell of a table, not the whole table. I used the pinch gesture, but not working on the table cell, working on the whole table.

I need to scale one cell at a time and when I want to enlarge the cell of the i-th cell automatically resize it?

Please help me.

Thanks in advance.

+3


source to share


4 answers


You can try the following code:

    // 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;

      

You can use this in a method didSelectRowAtIndexPath

.



In didSelectRowAtIndexPath:

write in the following code to get selectedcell

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

      

Now you have cell

+4


source


Have you tried writing @Devang response code inside

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

      



Hope it helps.

0


source


take a variable

NSInteger selectedindex

Now put this thing in

 - (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];
 }

      

You can use this method to enlarge / shrink a cell

  -(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


source


You can do it like this:

- (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];
}

      

Please replace CollectionViewCell with your own. I've implemented it with UICollectionView, but it's the same with UITableView.

0


source







All Articles