Jarron
Jarron

Reputation: 1049

If TouchLocation is NOT Within Bounds

For the below code, I need to see whether the touchLoaction is not within the bounds of a button, but the problem I have is a can't use !=, so I'm not 100% sure of what I need to enter instead. Every time I search the web for "if not equal", it only brings up the "!=" example, which doesn't work in this instance.

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")

}

Upvotes: 0

Views: 30

Answers (1)

Berendschot
Berendschot

Reputation: 3104

This should work: if (button.containsPoint(touchLocation) == False)

Declaration

Swift: func containsPoint(_ point: CGPoint) -> Bool

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

In both languages containsPoint returns a BOOL (which can be equal to false.)

Upvotes: 1

Related Questions