我试图实现捏和放大传递到控制器的图片,该控制器还包含一个滚动视图,如此处的教程所示:
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
最佳答案
我使用了相同的视频。问题是您需要将scrollView设置为委托。转到IB并控制,将scrollView拖动到视图控制器,然后选择Delegate。这应该解决它。
关于ios - 捏和缩放 swift ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33649665/