0

I would like to decrease the zooming speed behavior of a UIScrollView.

I've tried the solutions given in this two answers: Answer 1, Answer 2, but I'm not getting the expected results.

This is my implementation of answer 2:

- (void)scrollViewDidZoom:(UIScrollView *)scrollView {

    if(scrollView.multipleTouchEnabled){

        CGFloat fSpeedZoom = 2;
        CGFloat fMaxZoomScale = scrollView.maximumZoomScale;
        CGFloat fMinZoomScale = scrollView.minimunZoomScale;

        scrollView.maximumZoomScale = scrollView.zoomScale + fSpeedZoom;
        scrollView.minimumZoomScale = scrollView.zoomScale - fSpeedZoom;

        if(scrollView.maximumZoomScale > fMaxZoomScale){
            self.scrollView.maximumZoomScale = fMaxZoomScale;
        }

        if(scrollView.minimumZoomScale < fMinZoomScale){     
            self.scrollView.minimumZoomScale = fMinZoomScale;
        }
    }
}

If I keep the fSppedZoom values between 2 and 5 I get kind of an exponential behavior in which the further I try to zoom, the slower it zooms. I would like to get a linear behavior in which with a single parameter I could control the zooming speed.

Community
  • 1
  • 1
guardabrazo
  • 1,219
  • 1
  • 13
  • 26

1 Answers1

0

I would recommend against doing this.

When you drag, the point that was underneath your finger when the drag started stays underneath your finger as the drag pans. This remains the case until you reach the edge of the draggable area, at which time the point moves in the same direction as the pan, but not as far, to simulate resistance.

When you pinch to zoom, the same thing happens. The two points that were underneath your two fingers stay underneath your finger as the pinch moves (hence you can pan at the same time as zooming). Again, this only breaks down when further zooming is not possible.

If you break this touch-point relationship, user interactions feel alien and unnatural.

If you absolutely must do this, I would recommend, instead of trying to fight UIScrollView's built-in zooming behaviour, implementing your own pinch gesture recogniser and considering the relationship you want to achieve between the positions of your touches and the area of the scroll view you want to show.

hatfinch
  • 3,095
  • 24
  • 35