伙计们!我做一个像信使的应用程序,我可以发送/接收图像。点击图像后,应在另一个控制器(FullScreenImageVC)中打开它。在此控制器中,此图像必须具有实际尺寸,位于中心并且可以收缩以进行缩放。所有这些我以编程方式进行,没有任何库。
这是我的控制器,我从前一个VC接收图像,并在那里执行所有逻辑:
class FullScreenImageVC: UIViewController, UIScrollViewDelegate {
var startingFrame: CGRect?
var blackBackgroundView: UIView?
var startingImageView: UIImageView?
var imageToSave: UIImage?
var zoomingImageView: UIImageView = {
let image = UIImageView()
image.translatesAutoresizingMaskIntoConstraints = false
return image
}()
var scrollView: UIScrollView = {
let scroll = UIScrollView()
scroll.minimumZoomScale = 1
scroll.maximumZoomScale = 7
scroll.translatesAutoresizingMaskIntoConstraints = false
return scroll
}()
override func viewDidLoad() {
super.viewDidLoad()
scrollView.delegate = self
let imageView = UIImageView()
imageView.image = zoomingImageView.image
imageView.contentMode = .scaleAspectFit
imageView.isUserInteractionEnabled = true
view.addSubview(scrollView)
scrollView.addSubview(imageView)
scrollView.fillSuperView()
imageView.fillSuperView()
}
static func navigate(_ context: UIViewController, image: UIImageView) {
let vc = FullScreenImageVC()
vc.zoomingImageView = image
vc.hidesBottomBarWhenPushed = false
context.navigationController?.pushViewController(vc, animated: true)
}
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return self.zoomingImageView
}
}
这就是我现在得到的:link to GIF
请,任何帮助将不胜感激。