Actually these answers are really close to what I used, but I will post it separately, as it is different. Basically, zoomToRect does not work correctly if the target zoom scale matches the current one.
You can try to execute scrollToRect, but I had no luck with that.
Instead, just use contentOffset and set it to zoomRect.origin and the socket in the animation block.
[UIView animateWithDuration:duration delay:0.f options:UIViewAnimationOptionCurveEaseInOut animations:^{ if (sameZoomScale) { CGFloat offsetX = zoomRect.origin.x * fitScale; CGFloat offsetY = zoomRect.origin.y * fitScale; [self.imageScrollView setContentOffset:CGPointMake(offsetX, offsetY)]; } else { [self.imageScrollView zoomToRect:zoomRect animated:NO]; } } completion:nil];
cynistersix
source share