0
因此,我正在爲我的應用程序進行一些海關過渡,我有一個問題將自實例傳遞給呈現類的過渡代理。我知道問題與實例有關,因爲協議的方法沒有執行。傳遞一個類的實例
我想我錯過了一些東西,但我找不到。
的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)
}
}
您使用的故事板使用
detailVC
代替DetailVC()
?我認爲你需要在這個語句present(DetailVC(),animated:true,completion:nil)中使用'detailVC'而不是'DetailVC()'' – 3stud1ant3@ 3stud1ant3我知道我錯過了一些東西。是的,這是問題,謝謝! –