代码之家  ›  专栏  ›  技术社区  ›  E. Huckabee

不是Swift中此语句的运算符

  •  -2
  • E. Huckabee  · 技术社区  · 6 年前

    在我的项目中使用touchs方法做一些事情。我通常会这样设置我的触摸方法:

    override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
        for touch in touches {
            let location: CGPoint = touch.location(in: self)
        }
    }
    

    if myNode.contains(location) {
        // Do stuff in here
    }
    

    伪代码:

    if myNode does not contain(location) {
        // Do other stuff in here
    }
    

    我找不到这个版本,苹果文档对此也没什么好说的。

    2 回复  |  直到 6 年前
        1
  •  0
  •   rptwsthi    6 年前

    任何进入其他领域的东西都不是一个版本。

    现在,如果你正确地理解了你的问题,你有一个可触摸的精灵,如果它被触摸了,你想执行一个动作,否则就执行第二个动作。因此,在其他情况下,你可以写第二个行动。

    如果不是这样,那么请让我们知道具体的问题,这样我可以建议一个更合适的解决方案。

        2
  •  0
  •   ielyamani    6 年前

    myNode 不能用否定 !

    if !(myNode.contains(location)) {
        // Do stuff in here
    }