Donc, je suis en train de faire quelques transitions douanières pour mon application et j'ai un problème pour passer une instance personnelle au délégué de transition de la classe présentatrice. Je sais que le problème est lié à l'instance car les méthodes du protocole ne sont pas en cours d'exécution.Passer une instance d'une classe
Je présume qu'il me manque quelque chose mais je ne trouve pas quoi.
ViewController
class ViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
let detailVC = DetailVC()
let animationController = AnimationController()
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.delegate = self
collectionView?.dataSource = self
detailVC.transitioningDelegate = self
collectionView?.register(ControllerCell.self, forCellWithReuseIdentifier: "klk")
collectionView?.isPagingEnabled = false
collectionView?.contentInset = UIEdgeInsets(top: 0, left: 80, bottom: 0, right: 10)
let layout = collectionView?.collectionViewLayout as? UICollectionViewFlowLayout
layout?.scrollDirection = .horizontal
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "klk", for: indexPath) as! ControllerCell
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width * 0.6, height: view.frame.height * 0.5)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 100
}
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
animationController.originFrame = cell?.frame
present(DetailVC(), animated: true, completion: nil)
}
}
extension ViewController: UIViewControllerTransitioningDelegate {
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return animationController
}
}
DetailVC
class DetailVC: UIViewController {
var cellFrame: CGRect?
let label: UILabel = {
let lbl = UILabel()
lbl.textColor = .white
lbl.text = "Quitar"
lbl.frame = CGRect(x: 10, y: 10, width: 100, height: 100)
lbl.isUserInteractionEnabled = true
return lbl
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(label)
view.backgroundColor = .blue
label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(dismissing)))
}
func dismissing() {
dismiss(animated: true, completion: nil)
}
}
Utilisez-vous story-board? Je pense que vous devez utiliser 'detailVC' au lieu de' DetailVC() 'dans cette déclaration' present (DetailVC(), animé: true, completion: nil) ' – 3stud1ant3
@ 3stud1ant3 Je sais qu'il me manquait quelque chose. Oui c'était le problème, merci! –