捏和变焦迅速

时间:2015-11-11 11:33:45

标签: ios swift uiscrollview uiimageview pinchzoom

我正在尝试对传递到控制器的图片实施捏合和缩放,该控制器还包含按照教程中的滚动视图:

https://www.veasoftware.com/tutorials/2015/8/3/pinch-to-zoom-uiimageview-with-swift

我不确定我做错了什么。我的代码:

import UIKit
import Haneke

class imageZoomedController : UIViewController, UIScrollViewDelegate {


    @IBOutlet weak var imageView: UIImageView!
    var imageViewUrl : String?

    @IBOutlet weak var scrollView: UIScrollView!
    override func viewDidLoad()
    {
        super.viewDidLoad()
        self.scrollView.minimumZoomScale = 1.0
        self.scrollView.maximumZoomScale = 6.0
        self.imageView.userInteractionEnabled = true
        if let url = NSURL(string: imageViewUrl!) {
            print("url is \(url)")
            self.imageView!.hnk_setImageFromURL(url)
        }
    }

    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView?
    {
        return self.imageView!
    }


}

我可以在屏幕上看到图像但是捏合和缩放手势没有生效

更新

imageView的约束:

Align center X to superView = 0
Align center Y to superView = 0
Trailing to superView = 0
Leading to superView = 0
Bottom space to superView = 0
Top space to superView = 0

scrollView的约束:

Trailing space to superView = -20
Leading space to superView = -20
Top space to topLayoutGuide = 20
Bottom space to bottomLayoutGuide = 20
//also tried 0 for all these as per demo but same outcome

1 个答案:

答案 0 :(得分:1)

我使用了相同的视频。问题是您需要将scrollView设置为委托。转到您的IB并控制将scrollView拖动到视图控制器并选择Delegate。这应该解决它。

相关问题