2013-01-16 4 views
1

Я создаю приложение IOS.Основная анимация слева направо

Я пытаюсь сделать следующую основную анимацию

Текст 1 появляется в центре заменяется текстом 2, имея текст-двигаться слева направо, чтобы заменить текст 1 , а затем с текстом-перейти от слева направо, чтобы заменить текст 2 Затем текст с текстом 4 перемещается слева направо, чтобы заменить текст 3.

Каждый текст в основном перескакивает, чтобы заменить текст 1, 2, 3. Поэтому каждый текст устремляется, чтобы заменить предыдущий текст , Как это сделать?

ответ

0

Привет, вы можете использовать анимацию UIViewWithDuration: delay: options: animations: метод завершения для выполнения этих анимаций. Просто вставьте их внутри блоков завершения, чтобы связать их вместе. Я думаю, что они предназначены для iOS 3.2 и позже, хотя.

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... 
    }]; 
}]; 

Более подробная информация здесь http://developer.apple.com/library/ios/#documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html

+0

Блок, где представлены в iOS 4.0, но кто поддерживает меньше 4.3 в эти дни? –

0

Вы не упоминаете если вы используете UILabels или CATextLayers. Вот один из способов сделать это с CATextLayers:

Сначала создайте свой слой, который хотите оживить, и добавьте его в дерево слоев. Я сделал это в 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]; 
} 

Затем закрепите кнопку до этой розетки. Вы увидите анимацию push слева направо для каждого изменения свойства «string» текстового слоя.

- (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]]; 
} 

От того, что вы описали, это должно дать вам то, что вы ищете.

Смежные вопросы