【问题标题】:SDWebImage animate imagesSDWebImage 动画图像
【发布时间】:2014-08-31 04:32:34
【问题描述】:

我尝试了 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];

【问题讨论】:

  • 你得到什么错误?
  • -[__NSCFConstantString _isResizable]:无法识别的选择器发送到实例 0x2fce30(lldb)

标签: ios animation uiimageview nsarray sdwebimage


【解决方案1】:

我认为当您设置self.images1.animationImages = imagegallery 因为您的图像还无法加载时,method setImageWithURL:placeholderImage:completed: 是一个异步函数。你应该尝试另一种方式 喜欢: Animate images in uiimageview

【讨论】:

  • 是的,它有效,谢谢。无论如何,我需要大约 2-3 秒才能使用没有异步功能的图像移动到 ViewController。你以前用过这种方法吗?
  • 我认为不应该将 imageUrl 用于动画图像,相反,您可以加载一个 gif 图像 url 并设置为您的 imageView。 github.com/rs/SDWebImage/blob/master/SDWebImage/UIImage%2BGIF.h
【解决方案2】:

问题在于 imageGallery 包含字符串以及您在已完成块中添加的图像。首先没有理由将 imageGallery 设置为 animatee 的副本,因为您从不在 imageGallery 中使用这些字符串。只需为 imageGallery 创建一个新的空可变数组。

【讨论】:

  • 无论如何,如果我使用空的可变数组(如编辑问题)进行操作,它不会显示任何图像。如果我将更多 SdWebImage 添加到 NSMutableArray 中,是否可以将我的名为 images1 的 IBOutlet 属性用于所有这些?
  • @Milan1111,我不认为使用 setImageWithURL 真的是下载一系列图像的正确方法,因为它正在设置图像视图的图像——通过调用 3 次连续,您将图像更改三次,这实际上没有意义。我认为您没有获得图像,因为下载方法是异步的,并且 self.images1.animationImages = image gallery 行在图像返回之前正在运行。没用过SDWebImage,不知道用什么方法比较合适。
  • 不管怎样,谢谢大家帮忙,怎么想。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-18
  • 1970-01-01
  • 2012-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多