在不使用NSTimer的情况下在iOS中添加闪烁动画



我想在我的应用程序中添加一个闪烁动画。为此,我使用了下面的代码。

if (buttonFlashing) return;
        buttonFlashing = YES;
        self.img_one.alpha = 1.0f;
        [UIView animateWithDuration:0.12
                              delay:0.0
                            options:UIViewAnimationOptionCurveEaseInOut |
         UIViewAnimationOptionRepeat |
         UIViewAnimationOptionAutoreverse |
         UIViewAnimationOptionAllowUserInteraction
                         animations:^{
                             self.img_one.alpha = 0.0f;
                         }
                         completion:^(BOOL finished){
                             // Do nothing
                         }];
        mode_count=1;

隐藏和显示图像视图可以正常工作,但我想在隐藏图像时显示另一张图像,然后使用上面的代码再次显示以前的图像。上面的代码只是通过使用它的alpha来隐藏和显示图像视图。我该怎么做?

试试这段代码,

[UIView transitionWithView:self.imageView
                  duration:1.2f
                   options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAutoreverse |UIViewAnimationOptionRepeat
                animations:^{
                    self.imageView.image=[UIImage imageNamed:@"phone-icon.png"];
                } completion:NULL];

最新更新