在uiimageview中加载像gif这样的图像时出错

时间:2015-07-08 06:06:58

标签: ios objective-c iphone uiimageview gif

我想加载像gif这样的图片。当我通过push segue转到viewcontroller但是当我通过模态segue转到viewcontroller时,它不会在imageview中加载图像。

_ivDummy.animationImages = [NSMutableArray arrayWithObjects:
                                         [UIImage imageNamed:@"1.png"],
                                         [UIImage imageNamed:@"2.png"],
                                         [UIImage imageNamed:@"3.png"],
                                         [UIImage imageNamed:@"4.png"],
                                         [UIImage imageNamed:@"5.png"],
                                         [UIImage imageNamed:@"6.png"],
                                         [UIImage imageNamed:@"7.png"],
                                         [UIImage imageNamed:@"8.png"],
                                         nil];
    [_ivDummy setBackgroundColor:[UIColor redColor]];

    _ivDummy.animationDuration = 1.0f;
    _ivDummy.animationRepeatCount = INFINITY;
    [_ivDummy startAnimating];

请帮助我。

正在进行中

[indicator removeFromSuperview];
        UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 45.0f, 45.0f)];
        animatedImageView.animationImages = [NSMutableArray arrayWithObjects:
                                               [UIImage imageNamed:@"1.png"],
                                               [UIImage imageNamed:@"2.png"],
                                               [UIImage imageNamed:@"3.png"],
                                               [UIImage imageNamed:@"4.png"],
                                               [UIImage imageNamed:@"5.png"],
                                               [UIImage imageNamed:@"6.png"],
                                               [UIImage imageNamed:@"7.png"],
                                               [UIImage imageNamed:@"8.png"],
                                               nil];
        //[animatedImageView setBackgroundColor:[UIColor redColor]];

        animatedImageView.animationDuration = 1.0f;
        animatedImageView.animationRepeatCount = INFINITY;
        [animatedImageView startAnimating];
        indicator=animatedImageView;
        [self addSubview:indicator];

1 个答案:

答案 0 :(得分:0)

而不是使用
     - (void)viewDidLoad方法尝试使用
     - (void)viewWillAppear:(BOOL)动画

-(void)viewWillAppear:(BOOL)animated
{
    _ivDummy.animationImages = [NSMutableArray arrayWithObjects:
                                [UIImage imageNamed:@"1.png"],
                                [UIImage imageNamed:@"2.png"],
                                [UIImage imageNamed:@"3.png"],
                                [UIImage imageNamed:@"4.png"],
                                [UIImage imageNamed:@"5.png"],
                                [UIImage imageNamed:@"6.png"],
                                [UIImage imageNamed:@"7.png"],
                                [UIImage imageNamed:@"8.png"],
                                nil];
    [_ivDummy setBackgroundColor:[UIColor redColor]];
    _ivDummy.animationDuration = 1.0f;
    _ivDummy.animationRepeatCount = INFINITY;
    [_ivDummy startAnimating];
}

您可以覆盖此方法以执行与显示视图相关联的自定义任务。