0

I have made UIScrollView with three UIScrollViews inside and UImageView inside those three scollviews (Like in this answer: https://stackoverflow.com/a/25768875/2911156). Almost everything works, but zooming in landscape mode is broken. When user zoom in image, after zooming is finished, image is moved to the right edge and cut. How to center image after zoom, or what is wrong here?

UI Structure:

View hierarchy

Main Scroll view Constraints:

Main View Constraints

Image View constraint (all three had same pattern)

Image View Constraint

I'm not doing much in code (ScrollViews and ImageViews are based on autolayout), just done this:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return _photoImage;
}

and this:

- (void) setMaxMinZoomScaleForBonds {
    self.contentInset = UIEdgeInsetsZero; //need to reset it before load image, because previous insets can be wrong
    self.minimumZoomScale = 1.0;
    self.zoomScale =  1.0;
    self.maximumZoomScale = 2*[UIScreen mainScreen].scale;
}

One more thing done, but it does not work:

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale {
    //center image when zooming.
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;
    CGFloat screenHight = [[UIScreen mainScreen] bounds].size.height;
    CGFloat viewWidth = view.frame.size.width;
    CGFloat viewHight = view.frame.size.height;

    if(viewWidth < screenWidth)
            x = screenWidth/ 2;

    if(viewHight < screenHight)
            y = screenHight / 2 ;


    if(scale<=1.1)
        self.contentInset = UIEdgeInsetsZero;
    else
        self.contentInset = UIEdgeInsetsMake(y, x, y, x);
}

That is all related to zoom action.

Community
  • 1
  • 1
palusik
  • 111
  • 11
  • Can you post the code where you're doing this? – Chris Jan 15 '15 at 17:35
  • I've removed autolayout for UIImageView, now zoom and view is based on frame. Works perfectly. Couldn't get it working with pure autolayout. – palusik Feb 20 '15 at 11:39

0 Answers0