我创建了一个包含三个子视图的视图。
我想淡入/淡出三个子视图并无限期地重复效果。
我尝试类似:
+ (void)fadeIn:(UIView *)view withDuration:(float)duration
{
[UIView animateWithDuration:duration animations:^{
view.alpha = 1.0;
}];
}
+ (void)fadeOut:(UIView *)view withDuration:(float)duration
{
[UIView animateWithDuration:duration animations:^{
view.alpha = 0.0;
}];
}
[UIView animateWithDuration:5.0
delay:2.0
options:UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat
animations:^
{
[Utilities fadeOut:headSubtitle_1 withDuration:1];
[Utilities fadeIn:headSubtitle_2 withDuration:1];
[Utilities fadeOut:headSubtitle_2 withDuration:1];
[Utilities fadeIn:headSubtitle_3 withDuration:1];
[Utilities fadeOut:headSubtitle_3 withDuration:1];
[Utilities fadeIn:headSubtitle_1 withDuration:1];
}
completion:^(BOOL finished)
{}];
但效果不好。
我将获得的效果是:
- 显示 headSubtitle_1 2 秒
- 1 秒内淡出 headSubtitle_1
- 1 秒内淡入 headSubstitle_2
- 显示 headSubstitle_2 2 秒
- 1 秒内淡出 headSubtitle_2
- 1 秒内淡入 headSubstitle_3
- 显示 headSubstitle_3 2 秒
- 1 秒内淡出 headSubtitle_3
- 1 秒内淡入 headSubtitle_1
- 重复到 1。
非常感谢 !
编辑
最后,我尝试这样的事情:
+ (void)runAnimationSubtitleOrdersWithSub1:(UITextView *)headSubtitle_1 andSub2:(UITextView *)headSubtitle_2 andSub3:(UITextView *)headSubtitle_3
{
[UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
headSubtitle_1.alpha = 0;
} completion:^(BOOL finished) {
if (finished)
{
[UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
headSubtitle_2.alpha = 1;
} completion:^(BOOL finished) {
if (finished)
{
[UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
headSubtitle_2.alpha = 0;
} completion:^(BOOL finished) {
if (finished)
{
[UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
headSubtitle_3.alpha = 1;
} completion:^(BOOL finished) {
if (finished)
{
[UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
headSubtitle_3.alpha = 0;
} completion:^(BOOL finished) {
if (finished)
{
[UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
headSubtitle_1.alpha = 1;
} completion:^(BOOL finished) {
[FormBuilder runAnimationSubtitleOrdersWithSub1:headSubtitle_1 andSub2:headSubtitle_2 andSub3:headSubtitle_3];
}];
}
}];
}
}];
}
}];
}
}];
}
}];
}
真的很丑!如果有人知道更好的方法来做到这一点。