2013-09-26 44 views
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) 
{}]; 

但它不能很好地工作。

,我將得到的效果是:

  1. 顯示headSubtitle_1 2秒
  2. 淡出headSubtitle_1在1秒內
  3. 淡入headSubstitle_2在1秒內
  4. 顯示headSubstitle_2 2秒
  5. FadeOut headSubtitle_2在1秒內
  6. FadeIn headSubstitle_3在1秒內
  7. 顯示headSubstitle_3 2秒
  8. 淡出headSubtitle_3在1秒內
  9. 淡入headSubtitle_1在1秒內
  10. 重複爲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]; 
              }]; 
             } 
            }]; 
           } 
          }]; 
         } 
        }]; 
       } 
      }]; 
     } 
    }]; 
} 

這真是難看!如果有人知道更好的方法來做到這一點。

回答

2

也許你可以用幾個動漫嬉戲像這樣的東西(但,它不是漂亮):

_imageView.alpha = 0.0f; 
_imageView2.alpha = 0.0f; 
_imageView3.alpha = 0.0f; 


[UIView animateWithDuration:1 
         delay:0 
        options:UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat 
       animations:^{ 

        _imageView.alpha = 1.0f; 

        [UIView animateWithDuration:1 
              delay:1 
             options:UIViewAnimationCurveLinear | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat 
             animations:^{ 

              _imageView2.alpha = 1.0f; 

             } completion:^(BOOL finished) { 

              _imageView2.alpha = 0.0f; 

             } 
         ]; 


       } completion:^(BOOL finished) { 

        _imageView.alpha = 0.0f; 


       } 
]; 
0

看看[UIView beginAnimations:(NSString *) context:(void *)]