3

I want to zoom in/out only any one particular row/cell of table view not the whole table. I have used pinch gesture but its not working on table cell its working on whole table.

i need to zoom one cell at a time and when I want to zoom 2nd cell frist cell automitically resize then ?

Please help me out.

Thanks in advance.

Archana Chaurasia
  • 1,396
  • 3
  • 19
  • 35
  • i need your help after reading your quection i want same type of solution, here instead of particular cell i want to zoom UIImageview help me Note: without gesture it should auto zooming – Prashant09 Mar 21 '13 at 07:27

5 Answers5

3

You can try 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 on didSelectRowAtIndexPath method.

Under didSelectRowAtIndexPath: write in the following code to get the selected cell

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

Now you have got the cell

Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216
Devang
  • 11,258
  • 13
  • 62
  • 100
  • but in didSelectRowAtIndexPath from where I will get cell.contentview ? – Archana Chaurasia Mar 22 '12 at 12:27
  • @ArchanaChaurasia: I have edited Devang's answer and added Code to get the `cell` on `didSelectRowAtIndexPath:` method. – Parth Bhatt Mar 22 '12 at 12:33
  • its working but i don't want like this, i want zoom in/out very smooth like we does in a picture view with 2 fingers. – Archana Chaurasia Mar 22 '12 at 12:36
  • I have not tried that. But you can use scrollView for your data where 2 fingers zoom will be handled by itself. – Devang Mar 22 '12 at 12:39
  • @ArchanaChaurasia i think you have to work with scroll view for getting such type of zooming functinality. I have an idea in regards with that if you like you can try it My idea::"Make scroll view for each cell and use tag concept to diffentiate the scroll vw object and i think you can easily zoom in/ out with scroll view " ok thankx for giving me an such problem :) – Himanshu Agnihotri Jun 12 '12 at 11:20
1

You can do it like that:

- (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 yours. I have implemented it with UICollectionView but it is the same also with UITableView.

EgzonArifi
  • 830
  • 1
  • 11
  • 23
0

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 for zooming in/out 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){
      }]; 
      }
Jitendra Modi
  • 2,344
  • 12
  • 34
0

Swift 5

Disclaimer: it will zoom the whole tableView content. For zooming out repeat same with transformation scale value as 1.

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        let cell = tableView.cellForRow(at: indexPath) as! YourCellName
    
        let zoomView = cell.contentView.transform.scaledBy(x: 2, y: 2)
                view.transform = zoomView
        }

    }
-1

Have you tried writing @Devang answered code inside

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

Hope this helps.

Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216
hp iOS Coder
  • 3,230
  • 2
  • 23
  • 39