【问题标题】:Swift: Undefined symbols for architecture i386: "_OBJC_CLASS_$_CGColor"Swift:架构 i386 的未定义符号:“_OBJC_CLASS_$_CGColor”
【发布时间】:2014-06-26 16:50:59
【问题描述】:

我正在尝试为视图的背景颜色设置动画。在animationDidStop 委托方法中,我尝试使用CABasicAnimation 对象的toValue 属性设置最终背景颜色。代码在编辑器中似乎是正确的,但是当我编译项目时,链接器找不到CGColor 类。如果我省略 UIColor(CGColor: animation.toValue as CGColor!) 表达式(例如使用 const UIColor),则代码有效

class ViewController: UIViewController {

    @IBAction func colorSelected(sender: UIButton)
    {
        let animation = CABasicAnimation(keyPath: "backgroundColor")
        animation.toValue = sender.backgroundColor.CGColor
        animation.delegate = self
        self.view.layer.addAnimation(animation, forKey: "fadeAnimation")
    }

    @objc override func animationDidStop(anim: CAAnimation!, finished flag: Bool) {
        let animation = anim as CABasicAnimation
        self.view.backgroundColor = UIColor(CGColor: animation.toValue as CGColor!)
    }

}

更新:使用 Xcode 6 beta 3 代码编译,但在方法 swift_dynamicCastUnknownClassUnconditional 中引发异常,其中 toValue 属性被强制转换为 CGColor

这种奇怪的行为似乎与某些 Xcode 问题有关。

【问题讨论】:

    标签: ios core-animation swift cgcolor


    【解决方案1】:

    记住类是CGColorRef 而不是CGColor。 CGColor 是 UIColor 上获取 CGColorRef 的属性,例如 [UIColor redColor].CGColor

    【讨论】:

    • 重写为let color : CGColorRef = animation.toValue as CGColorRef self.view.backgroundColor = UIColor(CGColor: color) 我得到了同样的链接器错误
    • 不应该是self.view.backgroundColor = UIColor(CGColorRef: color)??
    【解决方案2】:

    这与编译器错误有关,Apple 在this 论坛帖子中已澄清。请求并提交了雷达:17603642。

    【讨论】:

      猜你喜欢
      • 2013-03-23
      • 2012-02-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多