问题描述
我需要全屏点击图像,因为其中一位开发人员建议使用此GSImageViewerController pod。
如果我仅安装pod "GSImageViewerController"
这样的Pod,并在我项目的swift文件中“导入GSImageViewerController”
像文档所述,我已经在下面的代码中写过
import UIKit
import GSImageViewerController
class ViewController: UIViewController {
@IBOutlet weak var tapImage: UIImageView!
override func viewDidLoad()
{
super.viewDidLoad()
let tapGestureRecognizer = UITapGestureRecognizer(target: self,action: #selector(imageTapped(tapGestureRecognizer:)))
tapImage.isUserInteractionEnabled = true
tapImage.addGestureRecognizer(tapGestureRecognizer)
}
@objc func imageTapped(tapGestureRecognizer: UITapGestureRecognizer)
{
let imageInfo = GSImageInfo(image: tapImage.image!,imageMode: .aspectFit)
let imageViewer = GSImageViewerController(imageInfo: imageInfo)
navigationController?.pushViewController(imageViewer,animated: true)
}
}
对于imageview控制器,我已经添加了navigationcontroller ..所以在这里,如果我点击图像然后全屏显示图像..但是就像文档所说的那样,如果我在屏幕上的任意位置点击或拖出图像,那么我就是为什么不能回到原来的位置?我在哪里错了???请帮忙
解决方法
您应该执行push
而不是present
。以下是我项目中的一个工作示例。
let imageInfo = GSImageInfo(image: profileImageView.image!,imageMode: .aspectFit)
let transitionInfo = GSTransitionInfo(fromView: profileImageView)
let imageViewer = GSImageViewerController(imageInfo: imageInfo,transitionInfo: transitionInfo)
present(imageViewer,animated: true,completion: nil)