【问题标题】:Error when load images like gif in uiimageview在uiimageview中加载像gif这样的图像时出错
【发布时间】:2015-09-25 21:28:15
【问题描述】:

我想加载像 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];

【问题讨论】:

  • 你在哪里写了这段代码,在 viewDidLoad 中?
  • @Mrunal yes in viewDidLoad
  • 这就是问题所在,应该在viewWillAppear 或者viewDidAppear 中。因为在那之前,你的 UIObjects 没有被正确初始化。所以你的 _ivDummy 对代码运行者来说是未知的。
  • @Mrunal 谢谢。现在它完全可以工作了,但是我为 MBprogresshud 之类的加载程序编写代码,而不是在上面工作。
  • 为此提出另一个问题,并提到您尝试过的代码。在此处让我知道您的新问题链接。

标签: ios objective-c iphone uiimageview gif


【解决方案1】:

而不是使用
- (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];
}

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

【讨论】:

  • 谢谢。它完全可以工作,但我为 MBprogresshud 之类的加载程序编写代码,但没有在上面工作。
  • 我有 mbprogesshud 但我不想使用它。我去设计自己的progesshud。
猜你喜欢
  • 2018-11-07
  • 1970-01-01
  • 2011-05-22
  • 1970-01-01
  • 2015-06-26
  • 2013-11-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多