Skip to content

Conversation

@geoffmacd
Copy link

For my project, I would like to use the same image caching solution between this image viewer and every other uiimageview in the project. This update allow me to do so. I've added two more samples to the sample app using SDWebimage for custom image caching.

Geoff MacDonald added 2 commits April 29, 2014 12:40
@jaredsinclair
Copy link
Owner

This looks really great! Welcome improvements. I have a few questions.

New Dependency?

So SDWebImage has only been included for the sample app, right? It's not an external dependency?

Naming

I think the new methods would benefit from more self-explanatory names. Something more like this:

- (instancetype)initWithImageInfo:(JTSImageInfo *)imageInfo
                             mode:(JTSImageViewControllerMode)mode
                  backgroundStyle:(JTSImageViewControllerBackgroundStyle)backgroundStyle
       customImageLoadingProgress:(NSProgress*)progress;

And this:

-(void)customImageLoadingDidFinish:(UIImage*)image;

NSProgress

Are there any potential conflicts when using an NSProgress to track progress? I don't understand from reading the docs how multiple unrelated NSProgress instances are resolved.

and replaced with NSURLSessionDownloadTask for clarity purposes
@geoffmacd
Copy link
Author

Dependancy

SDWebImage was intended as dependancy for sample app only of course as an example of why it is useful to have this custom progress initializer. However, I removed it entirely as I didn't want to add so many files to the repo and didn't want to create a podfile for just a sample app. Instead I modified the sample app to use NSProgress directly using NSURLSessionDownloadTask request and it's delegate methods to update progress.

Naming

I agree they needed to be more verbose and I commited your suggestions.

NSProgress

This object is simply used as a way to encapsulate the progression of a unit of work. It is used in AFNetworking which is what inspired this need. Read Matt Thompson's explanation

@jaredsinclair
Copy link
Owner

Thanks for the clarifications. I'm AFK at the moment, but I'm looking forward to trying this pull request out for myself. :-)

@jaredsinclair
Copy link
Owner

Adding a comment here.

@iaomw
Copy link

iaomw commented Nov 27, 2014

Hi @jaredsinclair , are you still merging that?

@LanceFu
Copy link

LanceFu commented Feb 20, 2015

I know this is old, but for those who are using JTSImageViewController and want to cache with SDWebImage, you can easily achieve it by using the JTSImageViewControllerDismissalDelegate to cache when the view dismisses.

This is what I am doing right now:

  • In the tap action on the UIImageView, check if image is cached:
- (void)tapImageViewAction:(id)sender {
    UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:imageURL.absoluteString];
    if (image) {
        JTSImageInfo *imageInfo = [[JTSImageInfo alloc] init];
        imageInfo.image = image;
        imageInfo.referenceRect = self.imageView.frame;
        imageInfo.referenceView = self.imageView.superview;
        JTSImageViewController *imageViewer = [[JTSImageViewController alloc]
                                               initWithImageInfo:imageInfo
                                               mode:JTSImageViewControllerMode_Image
                                               backgroundStyle:JTSImageViewControllerBackgroundOption_Scaled];
        [imageViewer showFromViewController:self transition:JTSImageViewControllerTransition_FromOriginalPosition];
    }
    else {
        JTSImageInfo *imageInfo = [[JTSImageInfo alloc] init];
        imageInfo.imageURL = imageURL;
        imageInfo.referenceRect = self.imageView.frame;
        imageInfo.referenceView = self.imageView.superview;
        JTSImageViewController *imageViewer = [[JTSImageViewController alloc]
                                               initWithImageInfo:imageInfo
                                               mode:JTSImageViewControllerMode_Image
                                               backgroundStyle:JTSImageViewControllerBackgroundOption_Scaled];
        imageViewer.dismissalDelegate = self;
        [imageViewer showFromViewController:self transition:JTSImageViewControllerTransition_FromOriginalPosition];
    }
}

If an image is returned, then you just pass it to JTSImageInfo and present the controller. If not, then you pass the URL and let JTSImageViewController handle the download.

  • Do the following to cache the image when image viewer dismissed:
- (void)imageViewerDidDismiss:(JTSImageViewController *)imageViewer {
    if (imageViewer.image) {
        [[SDImageCache sharedImageCache] storeImage:imageViewer.image forKey:imageURL.absoluteString];
    }
}

Hope this helps. I do think keeping JTSImageViewController as light as possible is better.

…wController

Conflicts:
	Sample App/JTSImageVC/JTSImageVC.xcodeproj/project.pbxproj
	Sample App/JTSImageVC/JTSImageVC.xcodeproj/project.xcworkspace/xcshareddata/JTSImageVC.xccheckout
	Sample App/JTSImageVC/JTSImageVC/Base.lproj/Main.storyboard
	Sample App/JTSImageVC/JTSImageVC/JTSViewController.h
	Sample App/JTSImageVC/JTSImageVC/JTSViewController.m
	Source/JTSImageViewController.m
@winzig
Copy link

winzig commented Nov 17, 2015

Is this PR still being considered for merging? I too am needing to download from a specialized source, and it would be nice to tap into the progress bar JTSImageViewController displays when it is in charge of downloading the image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants