This is a sample of how to zoom in and out on an image in a UIScrollView.
Pinch to make the image larger or smaller.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController, UIScrollViewDelegate { | |
var scrollView: UIScrollView! | |
var imageView: UIImageView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
scrollView = UIScrollView() | |
scrollView.frame = self.view.frame | |
scrollView.delegate = self | |
scrollView.maximumZoomScale = 3.0 | |
scrollView.minimumZoomScale = 1.0 | |
self.view.addSubview(scrollView) | |
imageView = UIImageView() | |
imageView.image = UIImage(named: "snorlax") | |
imageView.frame = scrollView.frame | |
scrollView.addSubview(imageView) | |
} | |
func viewForZooming(in scrollView: UIScrollView) -> UIView? { | |
return self.imageView | |
} | |
} |