2010-07-04 9 views
6

Quiero cambiar el tamaño de la celda seleccionada. Pero cambian la posición de la celda táctil.Al seleccionar Celda, UITableViewCell para cambiar el tamaño de la Celda

-  (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
UITableViewCell *currentCell = [aTableView cellForRowAtIndexPath:indexPath]; 

CGContextRef context = UIGraphicsGetCurrentContext(); 
[UIView beginAnimations:nil context:context]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationDelegate:currentCell]; 
[UIView setAnimationDidStopSelector:@selector(endAnimation)]; 

float extendedSize = currentCell.frame.size.height; 
currentCell.frame = CGRectMake(currentCell.frame.origin.x, currentCell.frame.origin.y, currentCell.frame.size.width, currentCell.frame.size.height + extendedSize); 

UITableViewCell *afterCell; 
for (int i=indexPath.row+1; i<=[aTableView numberOfRowsInSection:indexPath.section]; i++) { 
    afterCell = [aTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:indexPath.section]]; 
    afterCell.frame = CGRectMake(afterCell.frame.origin.x, (afterCell.frame.origin.y + extendedSize), afterCell.frame.size.width, afterCell.frame.size.height); 
} 
[UIView commitAnimations]; 

}

Gracias.

Respuesta

17

Sólo un simple ejemplo, pero usted consigue la idea:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [tableView beginUpdates]; 
    [tableView endUpdates]; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if([indexPath isEqual:[tableView indexPathForSelectedRow]]) { 
     return 88.0; 
    } 

    return 44.0; 
} 
+0

Este éxito. La animación funciona correctamente. Gracias. – tochi

+0

De nada. –

+2

if ([indexPath isEqual: [tableView indexPathForSelectedRow]]) – andrei200287

Cuestiones relacionadas