Dietmar Schwarz Webers
Dietmar Schwarz Webers

Reputation: 635

UIScrollView zoom move UIImageView moves image to left upper corner

I have a big image that I will allow to zoom = 10. When doing it the first time, the image zooms perfect, moving with one finger is also perfect. BUT, when trying to do a next zoom on the image, it jumps to x=0 y=0, and zooms.

I would like to stay the image on the x and y position, so that the user can go on zooming, like in Map app.

I have storyboard with

View - UIScrollView -- UIImageView

Added UIScrollViewDelegate and the following code:

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

Upvotes: 0

Views: 715

Answers (1)

Ajjjjjjjj
Ajjjjjjjj

Reputation: 675

see this if it can help you.... where drawingview is subview of scrollview. that can have multiple subviews

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    CGFloat offsetX = MAX((scrollView.bounds.size.width - scrollView.contentSize.width) * 0.5, 0.0);
    CGFloat offsetY = MAX((scrollView.bounds.size.height - scrollView.contentSize.height) * 0.5, 0.0);

    _drawingView.center = CGPointMake(scrollView.contentSize.width * 0.5 + offsetX,
                                 scrollView.contentSize.height * 0.5 + offsetY);


    return _drawingView;
}

Upvotes: 2

Related Questions