【问题标题】:If TouchLocation is NOT Within Bounds如果 TouchLocation 不在范围内
【发布时间】:2016-02-23 02:10:15
【问题描述】:

对于下面的代码,我需要查看 touchLoaction 是否不在按钮的范围内,但我遇到的问题是不能使用!=,所以我不能 100% 确定我需要什么改为输入。每次我在网上搜索“如果不相等”时,它只会显示“!=”示例,在这种情况下不起作用。

let touch = touches.first as UITouch!
let touchLocation = touch.locationInNode(self)

if button.containsPoint(touchLocation) { // NEEDS TO BE NOT CONTAINSPOINT OR SOMETHING

   print("not on button")

}

【问题讨论】:

    标签: swift if-statement sprite-kit contains


    【解决方案1】:

    这应该可以工作:if (button.containsPoint(touchLocation) == False)

    声明

    斯威夫特func containsPoint(_ point: CGPoint) -> Bool

    Objective-C- (BOOL)containsPoint:(CGPoint)point

    在两种语言中,containsPoint 返回一个 BOOL(可以等于 false。)

    【讨论】:

    • 太棒了,谢谢。我知道这个问题会有一个简单的答案,但我就是找不到。一旦允许(7 分钟时间),我会做出正确的答案。
    • @Jarron 如果此答案对您有所帮助,请考虑将其标记为“答案”。它可能会帮助其他人。
    • 是的,不过据说我必须等。
    • 或者干脆if !button.containsPoint(touchLocation) { ... }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多