重复淡入/淡出效果以在三个视图之间切换

时间:2013-09-26 09:43:52

标签: iphone ios objective-c animation

我创建了一个包含三个子视图的视图。

我想淡出/淡出三个子视图并无限期地重复这个效果。

我试着像:

+ (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. FadeOut headSubtitle_1 in 1秒
  3. 1秒内淡化headSubstitle_2
  4. 显示headSubstitle_2 2秒
  5. FadeOut headSubtitle_2 in 1 second
  6. 1秒内淡化headSubstitle_3
  7. 显示headSubstitle_3 2秒
  8. FadeOut headSubtitle_3 in 1 second
  9. 1秒内淡化headSubtitle_1
  10. 重复1。
  11. 非常感谢!

    修改

    最后,我尝试这样的事情:

    + (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 个答案:

答案 0 :(得分: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;


                 }
 ];

答案 1 :(得分:0)

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