1
我創建了一個包含三個子視圖的視圖。重複淡入/淡出效果以在三個視圖之間切換
我想淡入/淡出三個子視圖和無限重複的效果。
我嘗試類似:
+ (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秒
- 淡出headSubtitle_1在1秒內
- 淡入headSubstitle_2在1秒內
- 顯示headSubstitle_2 2秒
- FadeOut headSubtitle_2在1秒內
- FadeIn headSubstitle_3在1秒內
- 顯示headSubstitle_3 2秒
- 淡出headSubtitle_3在1秒內
- 淡入headSubtitle_1在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];
}];
}
}];
}
}];
}
}];
}
}];
}
}];
}
這真是難看!如果有人知道更好的方法來做到這一點。