我尝试了100多种使用SDWebImage动画图像的方法,但总是失败。我对使用积木了解得好吗?我有IBOutlet属性图像名称images1。我创建数组来存储值并为3个图像制作动画。
NSMutableArray *imagegallery = [[NSMutableArray alloc] init];
NSLog(@"IMAGES-%@", imagegallery);
[self.images1 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:@"Img1"]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[imagegallery addObject:image];
NSLog(@"Ima1-------%@", image);
}];
[self.images1 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:@"Img2"]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[imagegallery addObject:image];
}];
[self.images1 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:@"Img3"]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[imagegallery addObject:image];
}];
self.images1.animationImages = imagegallery; //this line gets error
self.images1.animationDuration = 0.5;
[self.view addSubview:self.images1];
[self.images1 startAnimating];
答案 0 :(得分:1)
问题是imageGallery包含字符串以及您在已完成的块中添加的图像。由于您从不在imageGallery中使用这些字符串,所以没有理由将imageGallery设置为animae的副本。只需为imageGallery创建一个新的空可变数组。
答案 1 :(得分:1)
我认为当您设置self.images1.animationImages = imagegallery
因为您的图片尚未加载时,method setImageWithURL:placeholderImage:completed:
是一个异步函数。你应该尝试另一种方式
喜欢:
Animate images in uiimageview