簡體   English   中英

Swift:體系結構i386的未定義符號:“ _ OBJC_CLASS _ $ _ CGColor”

[英]Swift: Undefined symbols for architecture i386: “_OBJC_CLASS_$_CGColor”

我正在嘗試為視圖的背景色設置動畫。 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的β3的代碼編譯,但一個例外方法被升高swift_dynamicCastUnknownClassUnconditional其中toValue屬性澆鑄到CGColor

這種奇怪的行為似乎與某些Xcode問題有關。

請記住,該類是CGColorRef而不是CGColor。 CGColor是UIColor的屬性,用於獲取CGColorRef,例如[UIColor redColor].CGColor

如Apple在論壇主題中所闡明的,這與編譯器錯誤有關。 請求並提交了雷達:17603642。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM