Есть ли способ открыть окно с длинным текстом при нажатии кнопки в каждой ячейке коллекции? - PullRequest
0 голосов
/ 26 апреля 2019

enter image description here У меня есть UICollectiobView, и при нажатии на ячейку он приводит меня к другому UIViewController с соответствующими данными.Но также как и в этой записи, я хочу нажать на кнопку в каждой ячейке, которая будет отображать длинный текст для каждой ячейки.

Как я показываю в этой записи, я добавил информационную кнопку в свою ячейку и хочуполучить правильные данные из моей модели для отображения длинного текста для каждой ячейки.

Это код для моей всплывающей анимации и didSelect в indexpath для ячеек.

import UIKit

let collectionViewReuseIdentifier = "collectionViewCell"

class MainViewController: UIViewController {

    @IBOutlet weak var collectionView: UICollectionView!
    @IBOutlet var infoView: UIView!
    @IBOutlet weak var danceFullDescription: UILabel!

    var dataSource = DataSource()

    override func viewDidLoad() {
        super.viewDidLoad()
        infoView.layer.cornerRadius = 10

        navigationItem.title = "Հայկական Պարեր"
    }

    func animateIn() {
        self.view.addSubview(infoView)
        infoView.center = self.view.center

        infoView.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
        infoView.alpha = 0

        UIView.animate(withDuration: 0.4) {
            self.infoView.alpha = 1
            self.infoView.transform = CGAffineTransform.identity
            self.collectionView.alpha = 0.3
        }
    }

    func animateOut() {
        UIView.animate(withDuration: 0.3, animations: {
            self.infoView.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
            self.infoView.alpha = 0
            self.collectionView.alpha = 1
        }) { (success: Bool) in
            self.infoView.removeFromSuperview()
        }
    }

    @IBAction func showInfo(_ sender: Any) {
        animateIn()
    }

    @IBAction func dismissPopup(_ sender: Any) {
        animateOut()
    }
}

extension MainViewController: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {

    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return dataSource.numberOfSections
    }

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

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: collectionViewReuseIdentifier, for: indexPath) as! DanceCollectionViewCell

        cell.dance = dataSource.danceForItemAtIndexPath(indexPath)

        // Layers
        cell.layer.masksToBounds = false
        cell.layer.shadowOffset = CGSize(width: 0, height: 1)
        cell.layer.shadowRadius = 3
        cell.layer.shadowColor = UIColor.black.cgColor
        cell.layer.shadowOpacity = 0.5
        cell.layer.cornerRadius = 15

        return cell
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

        let dance = dataSource.danceForItemAtIndexPath(indexPath)
        danceFullDescription.text = dance?.danceName
        performSegue(withIdentifier: "showDetail", sender: dance)
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "showDetail" {
            if let dest = segue.destination as? DetailViewController {
                dest.detailDance = sender as? Dance
            }
        }
    }
...