Vous ne mentionnez pas si vous utilisez UILabels ou CATextLayers. Voici une façon de le faire avec CATextLayers:
Créez d'abord votre calque que vous voulez animer et ajoutez-le à l'arborescence des calques. Je l'ai fait dans viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
_strings = @[@"Hello world", @"Goodbye cruel world", @"Hello again", @"And again, goodbye!"];
_textLayer = [CATextLayer layer];
[_textLayer setString:[_strings objectAtIndex:0]];
[_textLayer setBounds:CGRectMake(0.0f, 0.0f, 400.0f, 50.0f)];
[_textLayer setPosition:[[self view] center]];
[_textLayer setForegroundColor:[[UIColor orangeColor] CGColor]];
[_textLayer setAlignmentMode:kCAAlignmentCenter];
[[[self view] layer] addSublayer:_textLayer];
}
Ensuite, accrocher un bouton jusqu'à cette prise. Vous verrez une animation de poussée de gauche à droite pour chaque modification de la propriété 'chaîne' du calque de texte.
- (IBAction)didTapChangeText:(id)sender
{
NSInteger index = arc4random() % [_strings count];
CATransition *transition = [CATransition animation];
[transition setType:kCATransitionPush];
[transition setSubtype:kCATransitionFromLeft];
// Tell Core Animation which property you want to use the
// transition animation for. In this case 'string'
[_textLayer addAnimation:transition forKey:@"string"];
// Trigger the animation by setting the string property
[_textLayer setString:[_strings objectAtIndex:index]];
}
De ce que vous avez décrit, cela devrait vous donner ce que vous cherchez.
Bloc où introduire dans iOS 4.0, mais qui soutient moins de 4,3 de nos jours de toute façon? –