问题描述
我正在尝试进行图像预览,但是在ViewOnlyImageVC中查看图像时无法缩小图像
使用翠鸟从在线存储中检索图像,然后将其作为参数传递给ViewOnlyImageVC中的fullScreenImageView。
let selectimageVC = ViewOnlyImageVC()
let imageView = UIImageView().kf.setimage(with: URL(string: passedCallDetails.Call_Captured_Images[index]),placeholder: nil,options: nil,progressBlock: nil) { (image) in
switch image{
case .success(let result):
selectimageVC.fullScreenImageView.image = result.image
self.navigationController?.pushViewController(selectimageVC,animated: true)
case .failure(let error):
self.presentAlert(withTitle: "App name",message: error.localizedDescription)
}
}
图像预览VC代码
class ViewOnlyImageVC : UIViewController,uiscrollviewdelegate {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override var prefeRSStatusBarHidden: Bool {
return true
}
var navigationBar = NavigationBarView()
lazy var backBtn : ArrowBackButton = ArrowBackButton()
var imageScrollView : UIScrollView = {
let scrollImg = UIScrollView(frame:.zero)
scrollImg.translatesAutoresizingMaskIntoConstraints = false
return scrollImg
}()
var fullScreenImageView : UIImageView = {
let image = UIImageView(frame:.zero)
image.translatesAutoresizingMaskIntoConstraints = false
image.isUserInteractionEnabled = true
return image
}()
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
updateMinZoomScaleForSize(view.bounds.size)
}
}
//MARK: Button actions
extension ViewOnlyImageVC{
@objc func dismisspopup(sender: UIButton){
self.navigationController?.popViewController(animated: true)
}
}
//MARK: setup UI
extension ViewOnlyImageVC{
func setupUI(){
imageScrollView.delegate = self
fullScreenImageView.contentMode = .center
view.addSubview(navigationBar)
navigationBar.addSubview(backBtn)
view.backgroundColor = .white
backBtn.addTarget(self,action: #selector(dismisspopup(sender:)),for: .touchUpInside)
view.addSubview(imageScrollView)
imageScrollView.addSubview(fullScreenImageView)
NSLayoutConstraint.activate([
navigationBar.leftAnchor.constraint(equalTo: self.view.leftAnchor),navigationBar.rightAnchor.constraint(equalTo: self.view.rightAnchor),navigationBar.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),navigationBar.heightAnchor.constraint(equalToConstant: UIScreen.main.bounds.height * 0.1)
])
NSLayoutConstraint.activate([
backBtn.centerYAnchor.constraint(equalTo: navigationBar.centerYAnchor),backBtn.leftAnchor.constraint(equalTo: navigationBar.leftAnchor,constant: 20)
])
NSLayoutConstraint.activate([
imageScrollView.topAnchor.constraint(equalTo: navigationBar.bottomAnchor),imageScrollView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor),imageScrollView.leftAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leftAnchor),imageScrollView.rightAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.rightAnchor)
])
NSLayoutConstraint.activate([
fullScreenImageView.topAnchor.constraint(equalTo: imageScrollView.topAnchor),fullScreenImageView.bottomAnchor.constraint(equalTo: imageScrollView.bottomAnchor),fullScreenImageView.leftAnchor.constraint(equalTo: imageScrollView.leftAnchor),fullScreenImageView.rightAnchor.constraint(equalTo: imageScrollView.rightAnchor),])
}
func updateMinZoomScaleForSize(_ size: CGSize){
let scaleWidth = size.width / (fullScreenImageView.image?.size.width ?? 0)
let scaleHeight = size.height / (fullScreenImageView.image?.size.height ?? 0)
let minScale = min(scaleHeight,scaleWidth)
imageScrollView.minimumZoomScale = minScale
imageScrollView.zoomScale = minScale
}
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
return fullScreenImageView
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)