UIImageView淡出

时间:2014-08-08 18:08:52

标签: ios objective-c uiimageview

在我的主要故事板中,我有UIViewController隐藏UIImageView。我读了一个淡出图像的线程,我可以使用下面的代码。我想知道如何将我创建的UIImageViewIBAction绑定。

-(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 (strong, nonatomic) IBOutlet UIImageView *imageView;

2 个答案:

答案 0 :(得分:1)

您正在使用故事板,因此控制 - 将UIImageView拖入您的界面。该属性不需要很强 - 它应该是:@property (weak, nonatomic) IBOutlet UIImageView *imageView

如果您不知道如何进行控制拖动,则此视频可能有所帮助:https://www.youtube.com/watch?v=xq-a7e_l_4I。快进到2:05。

答案 1 :(得分:0)

打开助理编辑器

enter image description here

并按住Ctrl键并将UIImageView拖到文件顶部,以生成名为imageView的IBOutlet。您可以通过以下方式之一调用(调用)您的方法:

  • 如果您想在有人点击按钮时淡化图片,请从UIButton按住Ctrl键拖动到popupImage方法以制作IBAction
  • 如果您想以编程方式淡化图像,只需从代码中的任何位置{j}开始[self popupImage](例如,在viewDidLoad中)。在这种情况下,您不需要方法的IBAction部分,只需将其称为- (void)popupImage

由于您希望从头开始显示图像,因此不应将其设置为隐藏。

相关问题