UIImageView 淡出 [英] UIImageView fade out

查看:20
本文介绍了UIImageView 淡出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的主故事板中,我有一个带有隐藏 UIImageViewUIViewController.我在一个线程中读到要淡出图像的线程,我可以使用以下代码.我想知道如何将我用 IBAction 创建的 UIImageView 绑定起来.

In my main storyboard I have a UIViewController with a hidden UIImageView. I read in a thread that to fade an image out I could use the following code. I was wondering how to tie the UIImageView I created with an IBAction.

-(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;
    }];
}

我是否创建了一个 @property(强,非原子)IBOutlet UIImageView *imageView; 连接到图像?

Do I create a @property (strong, nonatomic) IBOutlet UIImageView *imageView; connected to the image?

推荐答案

打开辅助编辑器

并按住 ctrl 键将 UIImageView 拖到文件顶部以创建一个名为 imageView 的 IBOutlet.您可以通过以下方式之一调用(调用)您的方法:

and ctrl-drag form the UIImageView to the top of your file to make an IBOutlet called imageView. You can invoke (call) your method in one of these ways:

  • 如果您想在有人单击按钮时使图像淡化,请按住 ctrl 从 UIButton 拖动到 popupImage 方法以创建 IBAction.
  • 如果您想以编程方式淡化图像,只需在您希望淡化开始的代码中的任何位置执行 [self popupImage] (例如,在 viewDidLoad 中).在这种情况下,您不需要方法的 IBAction 部分,只需调用它- (void)popupImage.
  • If you want to fade the image when someone clicks a button, ctrl-drag from a UIButton to the popupImage method to make an IBAction.
  • If you want to fade the image programatically, just do [self popupImage] from wherever in your code you want the fade to begin (in viewDidLoad, for example). In this case, you don't need the IBAction part of your method, and can just call it - (void)popupImage.

因为您想从一开始就显示您的图像,所以不应将其设置为隐藏.

Since you want to show your image from the beginning, you should not have it set to hidden.

这篇关于UIImageView 淡出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆