Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 29th, 2013  |  syntax: None  |  size: 2.31 KB  |  views: 40  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  2.  
  3.        static NSString *CellIdentifier = @"Cell";
  4.        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  5.  
  6.        /** adding info to the cell **/
  7.  
  8.        UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(makeBiggerCell:)];
  9.        [cell addGestureRecognizer:pinchGesture];
  10.        return cell;
  11. }
  12.        
  13. - (void)makeBiggerCell:(UIPinchGestureRecognizer *)gesture {
  14.  
  15.       if (gesture.state == UIGestureRecognizerStateChanged){
  16.  
  17.           // I have a private property of NSIndexPath in order to keep
  18.           // track of the selected row.
  19.           self.selectedIndexPath = [self.tableView indexPathForCell:(UITableViewCell *)sender.view];
  20.  
  21.          CGPoint windowPoint = [gesture locationOfTouch:1 inView:nil];
  22.          CGPoint tablePoint =  [gesture locationInView:self.tableView];
  23.  
  24.  
  25.          self.sizeOfCell = fabsf(tablePoint.y - windowPoint.y);
  26.  
  27.          // the MINIMUM_CELL_SIZE is the regular size of the cell
  28.          // this conditional tries to avoid small tableviewcells
  29.          // IMPORTANT: as long as the user keeps his fingers on the cell
  30.          // the 'resize' happens
  31.  
  32.          if (self.sizeOfCell > MINIMUM_CELL_SIZE)
  33.             [self.tableView reloadRowsAtIndexPaths:@[self.selectedIndexPath] withRowAnimation:UITableViewRowAnimationNone];
  34.  
  35.      }else if (sender.state == UIGestureRecognizerStateEnded){
  36.  
  37.          if (sender.scale >=5) {
  38.             [self performSegueWithIdentifier:@"MySegue" sender:sender.view];
  39.          }
  40.       }
  41.  
  42. }
  43.        
  44. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  45.       if (self.selectedIndexPath && self.selectedIndexPath.row == indexPath.row && self.sizeOfCell)
  46.           return self.sizeOfCell + MINIMUM_CELL_SIZE;
  47. else
  48.          return MINIMUM_CELL_SIZE;
  49.   }
  50.        
  51. if (pinchGesture.state == UIGestureRecognizerStateChanged || pinchGesture.state == UIGestureRecognizerStateEnded) {
  52.     self.sizeOfCell.width *= pinchGesture.scale;
  53.     self.sizeOfCell.height *= pinchGesture.scale;
  54.     pinchGesture.scale = 1;
  55.     [self.tableView reloadRowsAtIndexPaths: @[self.selectedIndexPath] withRowAnimation:UITableViewRowAnimationNone];
  56. }
clone this paste RAW Paste Data