ios - didMove之间有什么区别(查看: SKView) and didMoveToView(view: SKView)?

标签 ios swift sprite-kit

如题所示,didMove(to view: SKView) 和 didMoveToView(view: SKView) 有什么区别?

我知道 didMoveToView 是方法,并且该 View 在旧(?)版本中属于 SKView 类型。我不明白将“查看:SKView”传递给 didMove 方法的处理。 “to”和“view”是分开的变量吗? “to”是“didMove”的一部分吗?这是怎么回事?

编辑:我知道他们都完成了同样的事情 - 但为什么“to”在参数通常所在的区域?这有什么好处吗?这似乎是不必要的并发症?

最佳答案

区别仅在于语法。

新的 Swift 3 语法是 didMove(to view: SKView)

在 Swift 中:

Each function parameter has both an argument label and a parameter name.The argument label is used when calling the function; each argument is written in the function call with its argument label before it. The parameter name is used in the implementation of the function. By default, parameters use their parameter name as their argument label.

func someFunction(argumentLabel parameterName: Int) {
    // In the function body, parameterName refers to the argument value
    // for that parameter.
}

所以,swift 3版本中的to只是参数标签


可能你也见过不需要插入参数名的函数。

如果您不需要参数的参数标签,请为该参数写一个下划线 (_) 而不是显式参数标签。

func someFunction(_ firstParameterName: Int, secondParameterName: Int) {
    // In the function body, firstParameterName and secondParameterName
    // refer to the argument values for the first and second parameters.
}
someFunction(1, secondParameterName: 2)

希望它有助于更​​好地理解这些修改:您可以找到更多详细信息 here

关于ios - didMove之间有什么区别(查看: SKView) and didMoveToView(view: SKView)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40580873/

相关文章:

ios - 使用 WKWebView 创建自定义 ORKStep

swift - 为什么没有调用协议(protocol)函数

ios - 使用 iOS Game Center Challenge 发送对象?

ios - (Swift) 将按钮移动到有异常(exception)的随机位置

iphone - 使用 JSON 字符串使用 RestKit 将对象手动加载到核心数据中

ios - 我会使用核心数据吗?

ios - CAShapeLayer,使用事务设置动画路径

swift - SpriteKit - 正在为所有图 block 更新 TileDefinition 和 userData?

ios - SpriteKit SKShapeNode 在重力碰撞时过早停止

ios - Swift 中的远程通知没有声音