mwaterfall / MWPhotoBrowser

A simple iOS photo and video browser with grid view, captions and selections.
MIT License
8.75k stars 2.72k forks source link

zoomPhotosToFill not display well on the MWPhotoBrowser (2.1.1) #485

Open billxie1988 opened 8 years ago

billxie1988 commented 8 years ago
    MWPhotoBrowser *photoBrowser = [[MWPhotoBrowser alloc]initWithDelegate:self];
    photoBrowser.displayActionButton = YES;
    photoBrowser.displayNavArrows = YES;
    photoBrowser.zoomPhotosToFill = YES;
    photoBrowser.enableSwipeToDismiss = YES;
    photoBrowser.hidesBottomBarWhenPushed = YES;
    [photoBrowser setCurrentPhotoIndex:index];
    [self.navigationController pushViewController:photoBrowser animated:NO];

but the photo was still zoom with some padding each side

Cubaker commented 8 years ago

same problem on iPhone 6 plus

billxie1988 commented 8 years ago
- (CGFloat)initialZoomScaleWithMinScale {
    CGFloat zoomScale = self.minimumZoomScale;
    if (_photoImageView && _photoBrowser.zoomPhotosToFill) {
        // Zoom image to fill if the aspect ratios are fairly similar
        CGSize boundsSize = self.bounds.size;
        CGSize imageSize = _photoImageView.image.size;
        CGFloat boundsAR = boundsSize.width / boundsSize.height;
        CGFloat imageAR = imageSize.width / imageSize.height;
        CGFloat xScale = boundsSize.width / imageSize.width;    // the scale needed to perfectly fit the image width-wise
        CGFloat yScale = boundsSize.height / imageSize.height;  // the scale needed to perfectly fit the image height-wise
        // Zooms standard portrait images on a 3.5in screen but not on a 4in screen.
        if (ABS(boundsAR - imageAR) < 0.17) {
            zoomScale = MAX(xScale, yScale);
            // Ensure we don't zoom in or out too far, just in case
            zoomScale = MIN(MAX(self.minimumZoomScale, zoomScale), self.maximumZoomScale);
        }
        zoomScale =  MIN(xScale, yScale);// when the pic is (300 191.5) the zoom shoud be 1.25 screen size is (375 ,667)
    }
    return zoomScale;
}

I find the zoomScale was not right on lansacpe picture

RunningYoung commented 8 years ago

@billxie1988 same problem on iPhone 6 plus Could you tell me how to solve?

billxie1988 commented 8 years ago
if (ABS(boundsAR - imageAR) < 0.17) {
            zoomScale = MAX(xScale, yScale);
            // Ensure we don't zoom in or out too far, just in case
            zoomScale = MIN(MAX(self.minimumZoomScale, zoomScale), self.maximumZoomScale);
        }
 zoomScale =  MIN(xScale, yScale);// when the pic is (300 191.5) the zoom shoud be 1.25 screen size is (375 ,667)
yanndupuy commented 8 years ago

@billxie1988 @Cubaker @RunningYoung

I have the same issue due to the fact on scale is done 4inch screen and more I find the following fixe which seems work on all iPhone screen size (iPhone 5, 6 & 6 Plus), send feedback if it's also OK in your case

All modification are in file "MWZoomingScrollView.m"

in Method "initialZoomScaleWithMinScale" add the following lines

// Zooms standard portrait images on a 3.5in screen but not on a 4in screen.
        if (ABS(boundsAR - imageAR) < 0.17) {
            zoomScale = MAX(xScale, yScale);
            // Ensure we don't zoom in or out too far, just in case
            zoomScale = MIN(MAX(self.minimumZoomScale, zoomScale), self.maximumZoomScale);
        }
        else // Screen size > 3.5in : Adapt according device orientation
        {
            if(UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation))
            {
                zoomScale = xScale; // scale to fit on screen width only in portrait mode
            }
            else
            {
                zoomScale = yScale; // scale to fit on screen height only in landscape mode
            }
        }

And then you must adapt method "setMaxMinZoomScalesForCurrentBounds" which compute 'contentOffSet' and in this case it's crappy but fix by the following lines :

CGFloat boundsAR = boundsSize.width / boundsSize.height; CGFloat imageAR = imageSize.width / imageSize.height;

// If we're zooming to fill then centralise
if (self.zoomScale != minScale &&  (ABS(boundsAR - imageAR) < 0.17)) {
    // Centralise
    self.contentOffset = CGPointMake((imageSize.width * self.zoomScale - boundsSize.width) / 2.0,
                                     (imageSize.height * self.zoomScale - boundsSize.height) / 2.0);
    // Disable scrolling initially until the first pinch to fix issues with swiping on an initally zoomed in photo
    self.scrollEnabled = NO;
}
else if ( (ABS(boundsAR - imageAR) > 0.17) ) // Screen size > 3.5in : Adapt according device orientation
{
    if(UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation))
    {
        // Centralise
        self.contentOffset = CGPointMake((imageSize.width * self.zoomScale - boundsSize.width) / 2.0,
                                         0.0);
    }
    else
    {
        // Centralise
        self.contentOffset = CGPointMake(0.0,
                                         (imageSize.height * self.zoomScale - boundsSize.height) / 2.0);
    }

    // Disable scrolling initially until the first pinch to fix issues with swiping on an initally zoomed in photo
    self.scrollEnabled = NO;
}
wiincgroup commented 8 years ago

same problem on iPhone 6 plus and 5s.

isacjoseph2006 commented 8 years ago

Try this by RunningYoung

// Image is smaller than screen so no zooming! // if (xScale >= 1 && yScale >= 1) { // minScale = 1.0; // }

purplepeng commented 7 years ago

It‘s great. It's works, I think this should be merged by author! @yanndupuy @billxie1988

MubeenQazi commented 6 years ago

This solution not working for video thumbnail. Anyone else facing this issue?