【发布时间】:2017-01-21 22:57:38
【问题描述】:
好的,我仍然是协议的新手,但我需要从另一个类调用一个函数(我知道在头类中调用该函数时有效)。
为此,在我调用该函数的类(它是一个 MSMessagesAppViewController)中,我有:
public protocol MSMessagesAppViewControllerDelegate: class {
func shrinkHeight(height:CGFloat)
func growHeight(height: CGFloat)
}
weak var delegate: MSMessagesAppViewControllerDelegate?
delegate?.shrinkHeight(height: 90)
然后我在class HeaderCollectionReusableView: UICollectionReusableView, MSMessagesAppViewControllerDelegate 中有实际功能:
func shrinkHeight(height:CGFloat)
{
print("WORKING!!"); //NOT printed
UIView.animate(withDuration: 0.7, delay: 0.0, usingSpringWithDamping:
0.6, initialSpringVelocity: 1.1, options: [], animations: {
//thing being animated
self.frame = CGRect(x: 0, y: 0, width: self.bounds.width, height: self.screenSize.height * (height/self.screenSize.height))
//change out
self.squareLogo.isHidden = true
self.logoLabel.isHidden = false
}, completion: { finished in
//code that runs after the transition is complete here
})
}
func growHeight(height:CGFloat)
{
它可以编译,但我知道上面的函数没有被调用,因为没有打印语句。我在这里做错了什么?
【问题讨论】:
标签: swift delegates swift3 protocols