【问题标题】:What is the type of SCNVector3 components? CGFloat or Float?SCNVector3 组件的类型是什么? CGFloat 还是浮点数?
【发布时间】:2015-03-08 17:58:36
【问题描述】:

苹果文档给出了 SCNVector3 的声明:

typedef struct SCNVector3 { CGFloat x, y , z; } SCNVector3;

或者在尝试编写重载函数时:

func * (left: SCNVector3, right: CGFloat) -> SCNVector3 {
    return SCNVector3Make(left.x * right, left.y * right, left.z * right)
}

我收到 “无法使用类型的参数列表调用 ''”错误。 left.x、left.y 和 left.z 不应该是 CGfloat 吗?

如何以及何时决定 CGFloat 是 double 还是 float?

【问题讨论】:

  • 该文档适用于 Objective-C
  • @DavidRönnqvist:但是 developer.apple.com/library/ios/documentation/SceneKit/… 对于 Objective-C 也是错误的(应该是 float 而不是 CGFloat)。如果选择“Swift”作为语言,则根本不显示任何类型。
  • 是的,我已经提交了雷达 :)

标签: ios swift scenekit


【解决方案1】:

在 iOS 8.1 SDK 标头中,SCNVectorX 类型基于 Float,可以看出 通过命令单击SCNVector3:

struct SCNVector3 {
    var x: Float
    var y: Float
    var z: Float
}

func SCNVector3Make(x: Float, y: Float, z: Float) -> SCNVector3

这与使用 CGFloat 的 OS X 10.10 SDK 不同。所以文档 似乎是错误的。以下在 iOS 项目中编译:

func * (left: SCNVector3, right: Float) -> SCNVector3 {
    return SCNVector3Make(left.x * right, left.y * right, left.z * right)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多