如何从另一个UICollectionViewCell更改标签的值

如果UILabel在A类中,并且将对其进行动画处理的didTapRightutton在B类中怎么办?

percentDiscountLabelRandomizeDealsCollectionViewCell中。如果我点击didTapRightutton在另一个名为RandomizeDealsViewController

的VC中,该动画会淡入淡出。

如何调用RandomizeDealsCollectionViewCell内部的函数来动画percentDiscountLabel?还有其他方法吗?

class RandomizeDealsCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var percentDiscountLabel: UILabel!

    func animatePercentDiscountLabel(deals: String) {

        self.percentDiscountLabel.alpha = 0.6
        self.percentDiscountLabel.isHidden = false
        UIView.animate(withDuration: 0.6,delay: 0,options: .curveeaseinout,animations: {
            self.percentDiscountLabel.alpha = 1.0
        }) { (isCompleted) in
        }
        percentDiscountLabel.text = deals
    }

}


class RandomizeDealsViewController: UIViewController {

private var centeredCollectionViewFlowLayout: CenteredCollectionViewFlowLayout!

    @IBaction func didTapRightButton(_ sender: Any) {
        guard let indexCard = centeredCollectionViewFlowLayout.currentCenteredPage else { return }
        if (indexCard > 0) {
             centeredCollectionViewFlowLayout.scrollToPage(index: indexCard + 1,animated: true)
             // should call the animation function here

        }
    }


}
haoyun1126 回答:如何从另一个UICollectionViewCell更改标签的值

如果indexCard是要设置动画的collectionViewCell的indexPath

您可以像->

那样呼叫您的手机

在RandomizeDealsViewController中

@IBAction func didTapRightButton(_ sender: Any) {
    guard let indexCard = centeredCollectionViewFlowLayout.currentCenteredPage else { return }
    if (indexCard > 0) {
         centeredCollectionViewFlowLayout.scrollToPage(index: indexCard + 1,animated: true)
        // should call the animation function here
        let cell = collectionView!.cellForItemAtIndexPath(indexCard) as? RandomizeDealsCollectionViewCell
        cell?.animatePercentDiscountLabel(deals: "deals")

    }
}
本文链接:https://www.f2er.com/3097677.html

大家都在问