У меня есть collectionview с массивом фото, нужно по тапу на фото передать их на другой collectionview и открыть на весь экран, аналог галереи

import UIKit

class FriendPhotoCollectionViewController: UICollectionViewController {

var friend: [UIImage]?
var photoGallery = makeFriends

override func viewDidLoad() {
super.viewDidLoad()

}

override func numberOfSections(in collectionView: UICollectionView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}

//кол-во ячеек в коллекции
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
return friend!.count
}
//добавляем массив фото в коллекцию
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PhotoCell", for: indexPath) as! FriendPhotoCollectionViewCell
cell.photosFriend.image = friend![indexPath.row]

return cell
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "SinglePhotoFriend" {
let cell = sender as! SinglePhotoCollectionViewCell
let indexPath = collectionView.indexPath(for: cell)!
let destination = segue.destination as! SinglePhotoViewController
destination.photoGallery.friendPhoto. = friend![indexPath.row]
}
}

// override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// if let vc = storyboard?.instantiateViewController(identifier: "SinglePhotoTableViewController" ) as? SinglePhotoViewController {
// vc.photoGallery.friendPhoto = photoGallery[indexPath.row]
// vc.indexPath = indexPath
// self.navigationController?.pushViewController(vc, animated: true)
// }
// }

}



import UIKit

class SinglePhotoViewController: UIViewController {

@IBOutlet weak var collectionView: UICollectionView!

var photoGallery: Friends!

var indexPath: IndexPath!

override func viewDidLoad() {
super.viewDidLoad()

title = photoGallery.friendName

collectionView.delegate = self
collectionView.dataSource = self
}
}
// MARK: - Table view data source

extension SinglePhotoViewController: UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

return photoGallery.friendPhoto.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SinglePhotoCell", for: indexPath) as! SinglePhotoCollectionViewCell
cell.SinglePhotoFriend.image = photoGallery.friendPhoto[indexPath.row]

return cell
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let frameCV = collectionView.frame

let widthCell = frameCV.width / CGFloat(1)
let heightCell = widthCell
return CGSize(width: widthCell, height: heightCell)
}

}

Ответы (0 шт):