ASMediaFocusManager icon indicating copy to clipboard operation
ASMediaFocusManager copied to clipboard

Better support for remote images

Open nnhubbard opened this issue 10 years ago • 4 comments

I am using a UICollectionView to show some thumbnail image from an API endpoint. When tapping on one, I use ASMediaFocusManager to show the full size image. However, it doesn't seem like there is very good remove image loading support, as it kind of loads, but it is blurry.

It seems like a much better solution would be to show a progress indicator on top of the tapped view. Then when the remove media is loaded, THEN show it in the focus manager.

nnhubbard avatar Apr 22 '15 23:04 nnhubbard

It should not be blurry as ASMediaFocusManager loads the image in the background form the URL you gave, and then shows it as soon as it is available. Can you check [ASMediaFocusManager loadImageFromURL:onImageView:] to see if the decoded image is the right one and has the right size? I suspect your URL to be wrong or to link to a small image instead of the full size image.

autresphere avatar Apr 23 '15 06:04 autresphere

I suspect that you are correct. However, for some reason when I use installOnView for my collectionViewCell imageView I never get any tap detection on the cell. But, if I call installOnView for the actual cell, it DOES work, but I have to also call mediaFocusManager:imageViewForView:, which is where I am going wrong and passing in the thumbnail rather than the full size URL. Here is what I have:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    ZSSPhoto *item = [self.items objectAtIndex:indexPath.row];
    ZSSPhotoCell *cell = (ZSSPhotoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionCell" forIndexPath:indexPath];
    __weak UIImageView *imageView = cell.imageView;
    imageView.contentMode = UIViewContentModeScaleAspectFill;

    if (item.image) {

        cell.imageView.image = item.image;

    } else {

        [imageView setImageWithURLRequest:[NSURLRequest requestWithURL:item.thumbURL] placeholderImage:[UIImage imageNamed:@"ZSSProfileImageViewDefault"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {

            [UIView transitionWithView:imageView
                              duration:0.23f
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                imageView.image = image;
                            } completion:nil];
            item.isLoaded = YES;

        } failure:nil];

    }

    [self.mediaFocusManager installOnView:cell];

    return cell;

}//end

- (UIImageView *)mediaFocusManager:(ASMediaFocusManager *)mediaFocusManager imageViewForView:(UIView *)view {

    ZSSPhotoCell *cell = (ZSSPhotoCell *)view;
    cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
    return cell.imageView;

}

- (NSURL *)mediaFocusManager:(ASMediaFocusManager *)mediaFocusManager mediaURLForView:(UIView *)view
{

    NSIndexPath *indexPath = [self.collectionView indexPathForCell:(ZSSPhotoCell *)view];

    // Here, medias are accessed through their name stored in self.mediaNames
    ZSSPhoto *item = [self.items objectAtIndex:indexPath.row];

    return item.mobileURL;
}

nnhubbard avatar Apr 23 '15 15:04 nnhubbard

First at all, thank you for awesome work that I can use this 3rd party libs for my application. I also have problem with loading image with URL, seems the self.focusViewController.mainImageView does not update even loadImageFromURL:onImageView: called. I also checked the method [ASMediaFocusManager decodedImageWithImage:] and it return the right size (in my case is 640 x 640) so I think there would be some problems about update the image after loading data from URL. Please fix it, I'm very appreciate.

dttson avatar Jun 30 '15 08:06 dttson

@dttson @nnhubbard @autresphere

PR #69 fixes the issue.

dogo avatar May 31 '16 13:05 dogo