stevex
stevex

Reputation: 5817

UIScrollView zooming on incorrect point

I have a UIScrollView with an image, and the image is in a container view. The view hierarchy looks like this:

UIScrollView
  UIView
    UIImageView

Panning works fine, but when I use the pinch gesture to zoom, the image changes size, but doesn't move relative to the origin, so the point centred underneath the two fingers moves as the gesture progresses. This makes it very difficult to zoom in on a particular point, since it's sliding away as you're zooming.

Description of the views involved:

<MyApp.MyView: 0x7ff6fd827e00; baseClass = UIScrollView; frame = (0 0; 375 667); autoresize = W+H; gestureRecognizers = <NSArray: 0x61800004a4d0>; layer = <CALayer: 0x618000023420>; contentOffset: {684, 487.5}; contentSize: {1731.4584832023011, 1154.3056554682007}>

<UIView: 0x7ff6fbe0c4d0; frame = (0 0; 1728 1152); transform = [2.2028669620902912, 0, 0, 2.2028669620902912, 0, 0]; layer = <CALayer: 0x6180000234c0>>

<UIImageView: 0x7ff6fbe09cd0; frame = (0 0; 1728 1152); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x618000023340>>

Animated Example

I have the UIImageView inside the UIView wrapper because I will have other views overlaid on the image which need to zoom/scale with the image.

There's very little of my own code running during the zoom. The UIScrollViewDelegate returns the UIView (the parent of the UIImageView), and configure the scroll view:

minimumZoomScale = 0.2
maximumZoomScale = 3.0
contentSize = image.size

Upvotes: 0

Views: 144

Answers (1)

Igor Kislyuk
Igor Kislyuk

Reputation: 330

Well, I've made a simple project that use your structure of views. And I didn't face with the problems. Possibly, you should check this things:

  • are auto layout constraints setting right way
  • is your parent view zooming correctly
  • is mode of UIImageView fitting your needs

    Hope this may help

    Upvotes: 1

  • Related Questions