2秒后显示和淡化UIImageView

fel*_*iao 27 xcode animation fadeout uiimage ios

我在我的iPhone游戏中正在开发一个通知系统,想要在屏幕上弹出一个图像并在2秒后自动褪色.

  1. 用户单击调用方法"popupImage"的按钮
  2. 屏幕上的图像出现在指定的位置,不需要淡入
  3. 在屏幕上显示2秒钟后,图像会自动淡出.

有没有办法做到这一点?提前谢谢.

Ali*_*are 55

使用UIView专用方法.

所以想象一下,你已经UIImageView准备好了,已经创建并添加到主视图中,但只是隐藏了.你的方法只需要让它可见,并在2秒后开始动画淡出它,通过将其"alpha"属性设置为1.0到0.0(在0.5s动画期间):

-(IBAction)popupImage
{
    imageView.hidden = NO;
    imageView.alpha = 1.0f;
    // Then fades it away after 2 seconds (the cross-fade animation will take 0.5s)
    [UIView animateWithDuration:0.5 delay:2.0 options:0 animations:^{
         // Animate the alpha value of your imageView from 1.0 to 0.0 here
         imageView.alpha = 0.0f;
     } completion:^(BOOL finished) {
         // Once the animation is completed and the alpha has gone to 0.0, hide the view for good
         imageView.hidden = YES;
     }];
}
Run Code Online (Sandbox Code Playgroud)

就那么简单!


Jos*_*raj 12

在Swift和XCode 6中

self.overlay.hidden = false
UIView.animateWithDuration(2, delay:5, options:UIViewAnimationOptions.TransitionFlipFromTop, animations: {
    self.overlay.alpha = 0
    }, completion: { finished in
    self.overlay.hidden = true
})
Run Code Online (Sandbox Code Playgroud)

覆盖是我的图像的出口.