I tried over 100 methods to animate images using SDWebImage but always fail. Do I understand good to using blocks? I am having IBOutlet property image names images1. I made array to store values and animate 3 images.
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];
I think when you set self.images1.animationImages = imagegallery because your image couldn't be loaded yet, method setImageWithURL:placeholderImage:completed: is an asynchronous function. you should try another way
like:
Animate images in uiimageview
The problem is that imageGallery contains strings as well as the images you add in the completed block. There's no reason to set imageGallery to be a copy of animatee in the first place since you never use those strings in imageGallery. Just create a new empty mutable array for imageGallery.
Related
in my application i am downloading an image from url from webservice using SDWebImage Library. I have nothing problem with this code
[imgQuestionContainer sd_setImageWithURL:[NSURL URLWithString:#"url"] placeholderImage:#"abc.png" options:SDWebImageProgressiveDownload];
with above code i have successfully load the image in imageview...
But my problem is that if i have url for the image but image is not available at that particular path of url. So, how to know that image is not available so i can load next data.
Thanks.
[cell.imageView setImageWithURL:[NSURL URLWithString:#"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]
success:^(UIImage *image) {
if(image){
}else{
}
}
failure:^(NSError *error) {
}];
];
This is what exactly i wanted.
[imgQuestionContainer sd_setImageWithURL:[NSURL URLWithString:[[arrOfLoadedPuzzel objectAtIndex:0] objectForKey:#"puzzle_question"]]
placeholderImage:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
{
if(error)
{
// image is not available
}
else
{
// image is available
}
}];
I've been trying to figure this out for the past hour and after endless searching can't seem to see the issue. I'm new to Objective-C development and have recently taken on a new codebase to use as a learning tool.
I'm trying to set an image to a cell which has a placeholder image and upon a completed request, sets the image to the bounds of the cell. However the code is failing because of the following error:
Incompatible block pointer types sending 'void (^)(UIImage *__strong, NSError *__strong, SDImageCacheType)'
Upon searching SO and other sources all I can find is ensuring that void is indeed returned. You can see from the code below that nothing is returned, thus it is void.
if(imageURL != nil)
{
cell.productImageView.contentMode = UIViewContentModeCenter;
__weak typeof(cell) weakCell = cell;
[cell.productImageView sd_setImageWithURL:imageURL placeholderImage:[UIImage sd_animatedGIFNamed:#"loading-indicator"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
if (image)
{
[weakCell.productImageView setContentMode:UIViewContentModeScaleAspectFill];
}
}];
}
Here is the header code for that particular item:
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
Thanks in advance!
The latest API of SDWebImage is slightly different so change your code for this one:
if(imageURL != nil)
{
cell.productImageView.contentMode = UIViewContentModeCenter;
__weak typeof(cell) weakCell = cell;
[cell.productImageView sd_setImageWithURL:imageURL placeholderImage:[UIImage sd_animatedGIFNamed:#"loading-indicator"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (image)
{
[weakCell.productImageView setContentMode:UIViewContentModeScaleAspectFill];
}
}];
}
How can I add 3 imageviews using SDWebImage into NSArray?
I have my images in this form:
[self.imageView1 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:#"image1"]]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
[self.imageView2 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:#"image2"]]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
[self.imageView3 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:#"image3"]]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
SDWebImage has another method with the completion block. Use that method
[self.imageView setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:#"image1"]]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
//completion code here ...
[self.animationArray addObject:image]; // animationArray is an array property
}];
Add the image to the animationArray from the completion block
If adding the 3 imageViews to your array is what you are aiming at then your second piece of code should be
NSArray *animationArray = [NSArray arrayWithObjects:self.imageView1, self.imageView2, self.imageView3, nil];
Although using the completion block is being suggested in the answer and maybe the best practice, this approach should also should manage fine considering that your imageWithURL call from SDWebImage will handle the network operation and update the objects when it receives the image.
I am trying to show progress view with SDWebImage but when i try below code then it return "0" in "receivedSize"
[cell. ImageHotDish setImageWithURL:[NSURL URLWithString:picName]
placeholderImage:[UIImage imageNamed:nil]
options:0 progress:^(NSUInteger receivedSize, long long expectedSize) {
NSLog(#"Downloaded = %#",receivedSize);
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[cell.ImageHotDish setImageWithURL:[NSURL URLWithString:picName]];
}];
I am getting null velue in "receivedSize"
Can any one tell me where i am doing wrong
I have already check this solution but its not showing progress but just an activity indicator. What i am trying to get how much image have been downloaded.
Show activity indicator in SDWebImage
I am using SDWebImage to cache my images. Overall it looks good but when I use setImageWithUrl method, it take a bit longer to bind the image back to my collection view. Is there a solution to this problem? I tried the following, but looks like it's still having the same problem.
__weak UIImageView *weakImageView = pictureImageView;
[pictureImageView setImageWithURL:[NSURL URLWithString:picture.attachment.url] placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
weakImageView.image = image;
}];