将集合视图单元格图像打开到新的ViewController中,然后滑动到下一个并使用Firebase Db中的图像缩放func图像库?

问题描述

搜索了几天结束,以查找是否有人在堆栈溢出之前问过这个问题,然后才问到这个问题。请指导我。 好的,所以我一直在尝试使用Firebase数据库创建图片库。我用所有图像填充了集合视图,但现在我不知道如何使用左,右滑动和缩放功能将这些图像打开到新的视图控制器中。我尝试使用启用了固定功能的集合视图,但效果不佳。如下所示。如果有人愿意帮我一个可以使用Firebase图像的GitHub库。 (我搜索了过去四天没有找到的内容。或者通过提供有关如何在具有缩放功能和滑动(滑块)的新ViewController中打开集合视图图像的示例代码来提供帮助。我搜索了一些GitHub库,但不知道如何将它们与情节提要一起使用(有些不兼容情节提要)

以下是我尝试执行此操作的代码: 具有集合视图(doceVC.swift)的gridview

import UIKit
import FirebaseDatabase
import CoreData
import Viewer



class SaveVC: UIViewController,UICollectionViewDataSource,UICollectionViewDelegate {

@IBOutlet weak var imageCollection: UICollectionView!

 var customImageFlowLayout: CustomImageFlowLayout!

  var images = [ChudoInsta]()

 var dbRef: DatabaseReference!


override func viewDidLoad() {
    
    super.viewDidLoad()
    
    
    dbRef = Database.database().reference().child("wedding/chudo_pics")

    loadDB()
       
      customImageFlowLayout = CustomImageFlowLayout()
       imageCollection.collectionViewLayout = customImageFlowLayout
       imageCollection.backgroundColor = .white
       

    
}


override func viewDidLayoutSubviews() {
       super.viewDidLayoutSubviews()
       
       customImageFlowLayout.setupLayout()
       dispatchQueue.main.async {
           self.imageCollection.reloadData()
       }
       
   }
   
  /* override func viewWillLayoutSubviews() {
       super.viewWillLayoutSubviews()
       customImageFlowLayout.setupLayout()
       
   } */
   
  
   
   func loadDB(){
       dbRef.observe(DataEventType.value,with: { (snapshot) in
           var newImages = [ChudoInsta]()
           
           for chudoInstaSnapshot in snapshot.children {
               let chudoInstaObject = ChudoInsta(snapshot: chudoInstaSnapshot as! DataSnapshot)
               newImages.append(chudoInstaObject)
           }
       
           self.images = newImages
       self.imageCollection.reloadData()
       })
   }

func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int {
    return images.count
}

func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = imageCollection.dequeueReusableCell(withReuseIdentifier: "Cell",for: indexPath) as! SaveCollectionViewCell
    
    let image = images[indexPath.row]
    
    
    cell.imageView.sd_setimage(with: URL(string: image.imageUrl),placeholderImage: UIImage(named: "image1"))
    
    return cell
   }

}

这就是我从Firebase检索它的方式:

firebase检索(ChudoInsta.swift)

import Foundation
import FirebaseDatabase

struct ChudoInsta {
let name:String!
let imageUrl:String!

let itemRef:DatabaseReference?

init(imageUrl:String,name:String) {
    self.name = name
    self.imageUrl = imageUrl
    self.itemRef = nil
}

init(snapshot:DataSnapshot) {
    name = snapshot.key
    //imageUrl = snapshot.key
    itemRef = snapshot.ref
    
    let snapshotValue = snapshot.value as? NSDictionary
    
    if let imageUrlC = snapshotValue?["imageUrl"] as? String {
        imageUrl = imageUrlC
    
    } else {
     imageUrl = ""
     }
    
   }

}

除此之外,我尝试制作一个单独的集合视图,在其中以视图控制器的大小在集合视图单元格中显示所有图像:

sliderfullimagecollection(DoceFullImageVIew.swift)

import UIKit
import Firebase
import FirebaseDatabase
import SDWebImage

class DoceFullImageVIew: UIViewController {


@IBOutlet weak var colltionView: UICollectionView!

 var images = [ChudoInsta]()

//  var imgArr = [ChudoInsta]()

var dbRef: DatabaseReference!



let viewImageSegueIdentifier = "doceImageSegueIdentifier"

override func viewDidLoad() {
    super.viewDidLoad()
    
    dbRef = Database.database().reference().child("wedding/doce_pics")

    loadDB()


    
    //printvalue()

    
   }

override func viewDidLayoutSubviews() {
       super.viewDidLayoutSubviews()
       
       //customImageFlowLayout.setupLayout()
       dispatchQueue.main.async {
           self.colltionView.reloadData()
       }
       
   }

   func loadDB(){
    dbRef.observe(DataEventType.value,with: { (snapshot) in
        var newImages = [ChudoInsta]()
        
        for chudoInstaSnapshot in snapshot.children {
            let chudoInstaObject = ChudoInsta(snapshot: chudoInstaSnapshot as! DataSnapshot)
            newImages.append(chudoInstaObject)
        }
    
        self.images = newImages
        self.colltionView.reloadData()
    })
  }



func printvalue() {
    
    print("This is the doce full image from firebase \(images)") // for testing purpose
   // print("This is the doce full image firebase \(images)")
   }

 }


extension DoceFullImageVIew: UICollectionViewDelegate,UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
  let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell",for: indexPath) as? DataCollectionViewCell
    
    let image = images[indexPath.row]
    
    cell?.img.sd_setimage(with: URL(string: image.imageUrl),placeholderImage: UIImage(named: "image1"))
    
    return cell!
      
      }

   }

  extension DoceFullImageVIew: UICollectionViewDelegateFlowLayout {

    func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout:              UICollectionViewLayout,sizeforItemAt indexPath: IndexPath) -> CGSize {
   let size = UIScreen.main.bounds
    return CGSize(width: size.height,height: size.width)
    
    
}

func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,insetForSectionAt section: Int) -> UIEdgeInsets {
    return UIEdgeInsets(top: 0,left: 5,bottom: 0,right: 5)
    //return UIEdgeInsets(0,5,5);
}

func collectionView(_ collectionView: UICollectionView,minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
    return 0
}

  func collectionView(_ collectionView: UICollectionView,minimumLinespacingForSectionAt section: Int) -> CGFloat {
   return 0
  }
  }

上面的代码产生的结果令人无法接受,看起来像这样切碎:https://drive.google.com/file/d/1Lk3jtuT06aKwYd5VF-WeMI91zPwyzOj1/view?usp=sharing

是横向模式,它显示半切碎的图像,例如:https://drive.google.com/file/d/14CE5V4WWTWWSBbrDp06KDnDPX7wd69VO/view?usp=sharing

我需要帮助,可以将集合视图图像打开到具有缩放比例的滑块中,该滑块可以在Firebase图像数据上实现

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)