autresphere / ASMediaFocusManager

iOS library to animate your image and video thumbnails to fullscreen.
MIT License
899 stars 158 forks source link

Image not zoomable due to async download of the large image #72

Open jeromeDms opened 7 years ago

jeromeDms commented 7 years ago

Hi I found an issue.

startFocusingView calls focusViewControllerForView in the above focusViewControllerForView, the large image is loaded asynchronously as follow: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self loadImageFromURL:url onImageView:viewController.mainImageView]; viewController.mainImageView.hidden = NO; }); While the image is downloading, the animation starts, at the end of the animation, the following function is called: [self.focusViewController focusDidEndWithZoomEnabled:self.zoomEnabled];

This function calls installZoomView which calls displayImage which calls configureForImageSize which calls setMaxMinZoomScalesForCurrentBounds

BUT

If the large image (async loading) is still not loaded from the server, zooming is not possible since setMaxMinZoomScalesForCurrentBounds results in maximumZoomScale = minimumZoomScale = 1.0 (calculation done on low resolution image, since the large image is still loading)

jeromeDms commented 7 years ago

My workaround is to call [self.focusViewController focusDidEndWithZoomEnabled:self.zoomEnabled]; once the large image has been loaded in focusViewControllerForView:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
      [self loadImageFromURL:url onImageView:viewController.mainImageView];
      if(viewController.scrollView.hidden == NO)
            {
                 viewController.mainImageView.hidden = NO;
                 dispatch_async(dispatch_get_main_queue(), ^{
                     [self.focusViewController focusDidEndWithZoomEnabled:self.zoomEnabled];
                     self.isZooming = NO;
                  });
         }
        });

and obviously remove below code from startFocusingView animation completion

[self.focusViewController focusDidEndWithZoomEnabled:self.zoomEnabled];

The above seems to work fine in my case, nobody observed a similar issue ?