UIImageView pinch zoom swift

前端 未结 13 740
误落风尘
误落风尘 2020-11-28 04:06

I was hoping someone could help me out. I am trying to allow a user to pinch zoom on a UIImageView(with a max and min level allowed). But for some reason the it does not wor

13条回答
  •  温柔的废话
    2020-11-28 04:51

    This is an old question but I don't see any answers that explain what is wrong with the original code.

    This line:

    let currentScale = self.view.frame.size.width / self.view.bounds.size.width
    

    Is working on the main view rather than the imageView so the scale calculation is always ~1

    This simple change makes it behave as expected

    let currentScale = sender.view!.frame.size.width / sender.view!.bounds.size.width
    

    by changing self to sender (and forcing view to unwrap) the scale calculation works as expected.

提交回复
热议问题