NeedsDisplayForKey / actionForKey覆盖是否正常工作? [英] are needsDisplayForKey/actionForKey overrides working correctly?

查看:71
本文介绍了NeedsDisplayForKey / actionForKey覆盖是否正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些在Objective-C中可用的代码转换为Swift。我遇到的问题是,needsDisplayForKey / actionForKey的调用方式不同。据我所知,自定义键值未正确传递。这是我调试时得到的结果:

I'm trying to convert some code that works in Objective-C to Swift. The problem I'm running into is that needsDisplayForKey/actionForKey aren't getting called the same way. As far as I can tell, the custom key values aren't getting passed in correctly. Here is what I get when I debug it:

默认值:

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

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

custom value (empty string passed in):

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

我不确定相关代码可能是什么。我只是问-其他人是否能够在Swift中定义自定义的隐式动画?从目标C移走时,我需要记住什么吗?

I'm not sure what the relevant code might be. I'll just ask - has anyone else was able to define a custom implicit animation in Swift? Is there anything I need to keep in mind when moving over from 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属性来在Swift中工作是Objective-C中的@dynamic属性)

I got this working in Swift by using @NSManaged attribute in front of the variable declaration (where you would use the the @dynamic attribute in Objective-C)

这篇关于NeedsDisplayForKey / actionForKey覆盖是否正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆