如果UILabel在A类中,并且将对其进行动画处理的didTapRightutton
在B类中怎么办?
percentDiscountLabel
在RandomizeDealsCollectionViewCell
中。如果我点击didTapRightutton
在另一个名为RandomizeDealsViewController
如何调用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
}
}
}