Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- /** adding info to the cell **/
- UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(makeBiggerCell:)];
- [cell addGestureRecognizer:pinchGesture];
- return cell;
- }
- - (void)makeBiggerCell:(UIPinchGestureRecognizer *)gesture {
- if (gesture.state == UIGestureRecognizerStateChanged){
- // I have a private property of NSIndexPath in order to keep
- // track of the selected row.
- self.selectedIndexPath = [self.tableView indexPathForCell:(UITableViewCell *)sender.view];
- CGPoint windowPoint = [gesture locationOfTouch:1 inView:nil];
- CGPoint tablePoint = [gesture locationInView:self.tableView];
- self.sizeOfCell = fabsf(tablePoint.y - windowPoint.y);
- // the MINIMUM_CELL_SIZE is the regular size of the cell
- // this conditional tries to avoid small tableviewcells
- // IMPORTANT: as long as the user keeps his fingers on the cell
- // the 'resize' happens
- if (self.sizeOfCell > MINIMUM_CELL_SIZE)
- [self.tableView reloadRowsAtIndexPaths:@[self.selectedIndexPath] withRowAnimation:UITableViewRowAnimationNone];
- }else if (sender.state == UIGestureRecognizerStateEnded){
- if (sender.scale >=5) {
- [self performSegueWithIdentifier:@"MySegue" sender:sender.view];
- }
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- if (self.selectedIndexPath && self.selectedIndexPath.row == indexPath.row && self.sizeOfCell)
- return self.sizeOfCell + MINIMUM_CELL_SIZE;
- else
- return MINIMUM_CELL_SIZE;
- }
- if (pinchGesture.state == UIGestureRecognizerStateChanged || pinchGesture.state == UIGestureRecognizerStateEnded) {
- self.sizeOfCell.width *= pinchGesture.scale;
- self.sizeOfCell.height *= pinchGesture.scale;
- pinchGesture.scale = 1;
- [self.tableView reloadRowsAtIndexPaths: @[self.selectedIndexPath] withRowAnimation:UITableViewRowAnimationNone];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement