Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class ViewController: UIViewController, UIScrollViewDelegate {
- let imageView = UIImageView(image: UIImage(named: "My Image"))
- @IBOutlet weak var scrollView: UIScrollView! {
- didSet {
- scrollView.delegate = self
- scrollView.addGestureRecognizer(UIRotationGestureRecognizer(target: self, action: "rotation:"))
- scrollView.contentSize = imageView.frame.size
- scrollView.addSubview(imageView)
- scrollView.maximumZoomScale = 5.0
- let heightScale = UIScreen.mainScreen().bounds.height / imageView.frame.size.height
- let widthScale = UIScreen.mainScreen().bounds.width / imageView.frame.size.width
- scrollView.minimumZoomScale = min(heightScale, widthScale)
- }
- }
- func rotation(recognizer: UIRotationGestureRecognizer) {
- switch recognizer.state {
- case .Changed:
- imageView.transform = CGAffineTransformMakeRotation(lastAngle + recognizer.rotation)
- case .Ended:
- lastAngle += recognizer.rotation
- default:
- break
- }
- }
- var lastAngle: CGFloat = 0
- func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
- return imageView
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement