Изменение текста UIButton titleLabel во время альфа равно 0.0f и избегать анимации текста
Я угасаю UIButton.titleLabel
в / из несколько раз, как это:
[UIView beginAnimations:@"fadeOutText" context:NULL];
[UIView setAnimationDuration:1.0];
button.titleLabel.alpha = 0.0f;
[UIView commitAnimations];
button.titleLabel.text = @"Changed text";
[UIView beginAnimations:@"fadeInText" context:NULL];
[UIView setAnimationDuration:1.0];
button.titleLabel.alpha = 1.0f;
[UIView commitAnimations];
Дело в том, что я хочу изменить текст в то время, когда он скрыт (альфа 0.0f). Но когда я возвращаю текст обратно, текст тоже оживляется. Его появление / перемещение справа от метки.
Есть ли способ избежать анимации текста?
Появление и исчезновение называются после друг друга, используя NSTimer
,
Спасибо!
2 ответа
Решение
Добавление отдельного раздела кода для изменения текста, похоже, удаляет анимацию текста.
Это, как я решил, может быть, есть лучшие решения?
-(void)hideText{
[UIView beginAnimations:@"fadeOutText" context:NULL];
[UIView setAnimationDuration:1.0];
button.titleLabel.alpha = 0.0f;
[UIView commitAnimations];
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(setText)
userInfo:nil
repeats:NO];
}
-(void)setText{
[button setTitle:@"changedText" forState:UIControlStateNormal];
[NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(showText)
userInfo:nil
repeats:NO];
}
-(void)showText{
[UIView beginAnimations:@"fadeInText" context:NULL];
[UIView setAnimationDuration:1.0];
button.titleLabel.alpha = 1.0f;
[UIView commitAnimations];
}
Попробуйте вот так:
[UIView animateWithDuration:1.0
animations:^{
button.titleLabel.alpha:0.0f;
}
completion:^(BOOL finished){
button.titleLabel.text = @"Changed text";
}
];
[UIView animateWithDuration:1.0
animations:^{
button.titleLabel.alpha:1.0f;
}
];