Рекурсивный animateWithDuration: анимации: завершение: метод iOS
Я пытаюсь заставить мой предмет "светиться" каждые 3 секунды, меняя его альфа с высокого на низкое значение и обратно. Однако он "мерцает" и в основном меняется каждые 0,2 секунды от цвета к цвету случайным образом. Я вставил метод ниже. Вероятно, это как-то связано с завершением, но не уверен?
-(void)showLoading{
[self.postTableView setHidden:YES];
self.isLoading = true;
//Disappear
[UIView animateWithDuration:1.5 animations:^(void) {
self.loadingLabel.alpha = 0.8;
self.loadingLabel.alpha = 0.3;
}
completion:^(BOOL finished){
//Appear
[UIView animateWithDuration:1.5 animations:^(void) {
self.loadingLabel.alpha = 0.3;
self.loadingLabel.alpha = 0.8;
}completion:^(BOOL finished2){
if(true){
[self showLoading];
}
}];
}]; }
2 ответа
Решение
self.loadingLabel.alpha = .8;
[UIView animateWithDuration:1.5 delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
self.loadingLabel.alpha = .3;
} completion:nil];
UIViewAnimationOptionAutoreverse и UIViewAnimationOptionRepeat могут помочь вам.
Вы можете остановить это
self.loadingLabel.alpha = .8;
или другая анимация.
[UIView animateWithDuration:1.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.loadingLabel.alpha = .8;
} completion:nil];
UIViewAnimationOptionBeginFromCurrentState - это полезная опция для остановки анимации с помощью другой анимации.
-(void)viewDidLoad{
//use schedule timer to call repeatedly showLoading method until loading done
}
-(void)showLoading{
[self.postTableView setHidden:YES];
self.isLoading = true;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.loadingLabel.alpha = 0.3;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.loadingLabel.alpha = 0.8;
[UIView commitAnimations];
}