12
我收到以下错误问题在Swift 3中设置CABasicAnimation委托?
无法分配型“StarButton”键入 的价值“CAAnimationDelegate?
这个CABasicAnimation块的最后一行:
let fillCircle = CABasicAnimation(keyPath: "opacity")
fillCircle.toValue = 0
fillCircle.duration = 0.3
fillCircle.setValue(notFavoriteKey, forKey: starKey)
fillCircle.delegate = self // this is where the error is thrown
self
是一个自定义的UIButton类。这在Swift以前的版本中不是问题...有关解决方案的任何建议?
UPDATE
这里是可下载链接到源文件的StarButton类最佳参考:
https://www.dropbox.com/s/gvc2sky05f4p3au/StarButton.swift?dl=0
你确定它符合委托协议吗? – Fogmeister
Apple Docs中的'UIButton'(https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/)不符合'CAAnimationDelegate'。你有没有明确说你的子类是一个代表?请参阅http://stackoverflow.com/questions/24024466/how-do-i-make-a-class-conform-to-a-delegate-in-swift – Doc
@Fogmeister这是我抓取的一个开源组件的一部分&检查完文件后,它似乎没有任何协议..但是,这工作得很好2.xx –