I'm trying to add an image and scrollview programmatically to swift, and then allow them to be pinched to zoom.
I've followed the instructions from UIImageView pinch zoom swift but am still not able to pinch to zoom, I'm not sure what I'm missing
class mapViewController: UIViewController, UIScrollViewDelegate, IALocationManagerDelegate {
var imageViewBackground: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let width = UIScreen.main.bounds.size.width
let height = UIScreen.main.bounds.size.height
let imageViewBackground = UIImageView(frame: CGRect(x:0, y:0, width:width-70, height:height-60))
var image: UIImage?
let urlString = "https://firebasestorage.googleapis.com/v0/b/coxur-59760.appspot.com/o/Maps%2FCapture.png?alt=media&token=741b1425-cb01-453b-8c40-47f6e5fd528d"
let url = NSURL(string: urlString)! as URL
if let imageData: NSData = NSData(contentsOf: url) {
image = UIImage(data: imageData as Data)
}
imageViewBackground.image = image
// you can change the content mode:
imageViewBackground.contentMode = UIView.ContentMode.scaleAspectFill
var scrollView: UIScrollView!
scrollView = UIScrollView(frame: CGRect(x: 0, y: 120, width: width, height: height))
scrollView.contentSize = CGSize(width: width, height: 2000)
scrollView.delegate = self
scrollView.minimumZoomScale = 1.0
scrollView.maximumZoomScale = 6.0
scrollView.addSubview(imageViewBackground)
self.view.addSubview(scrollView)
//self.view.sendSubviewToBack(imageViewBackground)
}
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return imageViewBackground
}
}
What am I doing wrong here?