needsDisplayForKey / actionForKey是否覆盖正常工作?

时间:2014-06-10 20:26:23

标签: calayer swift

我试图将一些在Objective-C中工作的代码转换为Swift。我遇到的问题是needDisplayForKey / actionForKey没有以相同的方式调用。据我所知,自定义键值未正确传递。这是我调试它时得到的结果:

默认值:

(String!) event = {
  core = {
    _baseAddress = Builtin.RawPointer = 0x00feee51 "onOrderIn"
    _countAndFlags = 1073741833
    _owner = Some {
      Some = (instance_type = Builtin.RawPointer = 0x01026348 @"onOrderIn")
    }
  }
}

自定义值(传入空字符串):

(String!) event = {
  core = {
    _baseAddress = Builtin.RawPointer = 0x0b418f79
    _countAndFlags = 1073741833
    _owner = Some {
      Some = (instance_type = Builtin.RawPointer = 0x0b418f70 -> 0x006e38f0 (void *)0x006e38c8: __NSCFString)
    }
  }
}

我不确定相关代码是什么。我只是问 - 有没有其他人能够在Swift中定义自定义隐式动画?从Objective C移开时我还需要记住什么吗?

override class func needsDisplayForKey(key: String!) -> Bool{
    if key == "angleFrom" || key == "angleTo" {
        return true;
    }
    return super.needsDisplayForKey(key)
}

override func actionForKey(event: String!) -> CAAction!{
    if event == "angleFrom" || event == "angleTo" {
        return self.makeAnimationForKey(event)
    }
    return super.actionForKey(event)
}

1 个答案:

答案 0 :(得分:13)

我在Swift中使用@NSManaged属性在变量声明前面(在Objective-C中使用@dynamic属性)