我正在将一些Objective-C代码转换为Swift代码,我遇到了以下问题:
目标-C代码是
SCNNode *textNode = [SCNNode nodeWithGeometry:text];
textNode.transform = CATransform3DInvert(self.chartNode.worldTransform);
这是我尝试转换的代码:
let textNode = SCNNode(geometry: text)
textNode.transform = CATransform3DInvert(self.chartNode.worldTransform)
但是,我收到错误:' SCNMatrix4无法转换为CATransform3D'
我意识到CATransform3DInvert接受CATransform3D类型的参数,而我包含的参数是SCNMatrix4类型。
我尝试了以下演员尝试:
textNode.transform = CATransform3DInvert(CATransform3D(self.chartNode.worldTransform))
但这不起作用。
然后我发现CATransform3D和SCNMatrix4都是结构体,我不确定如何从一个结构转换到另一个结构(或者甚至可以在Swift中的结构之间进行转换?)
也许有另一种更简单的方法?
任何帮助将不胜感激 - 谢谢。
答案 0 :(得分:3)
确定,
Airspeed Velocity提供的链接有一个很好的解释,很容易转换为Swift(实际上它是相同的)。
CATransform3D等基于Mac OS X,不适用于iOS - 而是使用iOS SCNMatrix4等。 在链接的帖子 - 头文件中,您可以找到使用的类型是SceneKitTypes.h - 如果您想在github上查看副本:https://github.com/andymatuschak/Khan-Academy-Offer-Acceptance-Toy/blob/master/§/SceneKitTypes.h
我使用SCNMatrix4Invert作为上面提到的rintaro并且它有效。
所以,现在使用的Swift代码是:
let textNode = SCNNode(geometry: text)
textNode.transform = SCNMatrix4Invert(self.chartNode.worldTransform)