calayer – needsDisplayForKey / actionForKey覆盖正常工作?

前端之家收集整理的这篇文章主要介绍了calayer – needsDisplayForKey / actionForKey覆盖正常工作?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试将一些在Objective-C中工作的代码转换为 Swift.我遇到的问题是needsDisplayForKey / 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)
}
我通过在变量声明前面使用@NSManaged属性(在Objective-C中使用@dynamic属性)在Swift中使用它
原文链接:https://www.f2er.com/swift/319455.html

猜你在找的Swift相关文章