2

Hey les gars, (relativement, je crois) question simple ici,Animer l'insertion imageView de UITableViewCell?

J'ai un UITableViewController avec son UITableView, avec son nombre déterminé de cellules. Si un utilisateur tape sur une cellule, une image est insérée dans la propriété imageView de cellule respective, comme suit:

[self.tableView cellForRowAtIndexPath:chosenPersonIndexPath].imageView.image = [UIImage imageNamed:@"tick.jpeg"]; 

(où chosenPersonIndexPath est tout simplement le chemin d'index de cellule sélectionnée)

Est-il possible d'animer ce? En tant que tel, le UITableViewController colle simplement dans l'image sans aucune transition. Tout ce que je demande, c'est s'il y a un moyen d'animer cela, et si oui, comment?

Merci beaucoup d'avance! ~ Joaquim

Répondre

1

Étant donné que les instances UIImageView sont des instances UIView, vous pouvez les animez comme tout autre UIView:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    cell.imageView.alpha = 0.0; 
    cell.imageView.image = [UIImage imageNamed:@"tick.jpg"]; 
    cell.textLabel.text = @"tap!"; 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.4]; 
    [self.tableView cellForRowAtIndexPath:indexPath].imageView.alpha = 1.0; 
    [UIView commitAnimations];  
} 

L'animation dans le tableView: didSelectRowAtIndexPath: méthode pourrait inclure flips, des changements de taille, ou tout autre type de changement de propriété (animable). Consultez le chapitre "Animatable Properties" dans le "Core Animation Programming Guide" dans la documentation de l'iPhone SDK pour plus d'informations.

Espérons que cela aide!

+0

Génial! C'est exactement ce que je cherchais. Merci beaucoup de votre patience pour répondre à la question «newbish» d'un jeune rookie de 16 ans. : D Joyeux 2010! – wakachamo

+0

Pas de problème! :) heureux de vous aider. –