2013-01-16 4 views
1

Je construis une application IOS.Animation de base de gauche à droite

Je suis en train de faire l'animation de base suivant

Texte 1 apparaît au centre ensuite remplacé par le texte 2 en ayant du texte 2 se déplacent de gauche à droite pour remplacer le texte 1 Et puis d'avoir du texte 3 passage de De gauche à droite pour remplacer le texte 2 Ensuite, le texte 4 doit être déplacé de gauche à droite pour remplacer le texte 3.

Chaque texte saute essentiellement pour remplacer le texte 1, 2, 3. Chaque texte se substitue donc au texte précédent . Comment puis-je accomplir cela?

Répondre

0

Bonjour, vous pouvez utiliser la méthode animateWithDuration: delay: options: animations: achèvement d'UIView pour effectuer ces animations. Il suffit de les imbriquer dans les blocs d'achèvement pour les enchaîner. Je pense qu'ils sont pour iOS 3.2 et plus tard seulement.

UILabel *labelText2; // Can be set up in Interface Builder, linked as IBOutlet 
CGRect rectLabel2 = labelText2.frame; 
rectLabel2.center = labelText2.superview.center; 

[UIView animateWithDuration:1.0f delay:0.0f options:nil animations:^(){ 
    labelText2.frame = rectLabel2; // Animates labelText2 to the center of its container view 
} completion:^(BOOL finished) { 

    // Continue with other animation using another UIView animateWithDuration block... 
    UILabel *labelText3; // Setup in Interface Builder on the left outside of the container view 
    CGrect rectLabel3 = labelText3.frame; 
    rectLabel3.center = labelText3.superview.center; 

    [UIView animateWithDuration:1.0f delay:0.0f options:nil animations:^(){ 
    labelText3.frame = rectLabel3; 

    } completion:^(BOOL finishedInside) { 
    // Nest in Label4, Label5 etc... 
    }]; 
}]; 

Plus d'informations ici http://developer.apple.com/library/ios/#documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html

+0

Bloc où introduire dans iOS 4.0, mais qui soutient moins de 4,3 de nos jours de toute façon? –

0

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.

Questions connexes