I have a scrollview in swift 3. The zoom is not working. I have set up the scrollview and put an imageview inside. I have set self as the delegate and implemented viewForZoomingInScrollView. please take a look. thanks.
edit: another thing I didn't mention before was that this is view in a navigation controller. would that affect it?
class FlowDiagramViewController: UIViewController, UIScrollViewDelegate {
var scrollView: UIScrollView!
var imageView:UIImageView! = UIImageView()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let image = UIImage(named: "flowNewRotated1242x2208.png")
imageView = UIImageView(image: image)
setupPictureWithZoom()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func setupPictureWithZoom() {
// http://stackoverflow.com/questions/30014241/uiimageview-pinch-zoom-swift
imageView.frame = CGRect(x: 0, y: 0, width: 1242, height: 2208)
// imageView.transform = imageView.transform.rotated(by: CGFloat(M_PI_2))
imageView!.layer.cornerRadius = 11.0
imageView!.clipsToBounds = false
scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height))
scrollView.minimumZoomScale = 0.25
scrollView.maximumZoomScale = 5.0
scrollView.delegate = self
scrollView.backgroundColor = UIColor(red: 90, green: 90, blue: 90, alpha: 0.90)
scrollView.alwaysBounceVertical = false
scrollView.alwaysBounceHorizontal = false
scrollView.showsVerticalScrollIndicator = true
scrollView.flashScrollIndicators()
scrollView.contentSize = CGSize(width: 1242, height: 2208)
scrollView.addSubview(imageView!)
view.addSubview(scrollView!)
scrollView.setZoomScale(0.25, animated: true)
}
func viewForZoomingInScrollView(scrollView: UIScrollView!) -> UIView! {
return imageView
}
}
I have tried both defining the scrollview in the storyboard and in code.