【发布时间】: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