Is there a way to verify if a CGPoint
is inside a specific CGRect
.
An example would be:
I\'m dragging a UIImageView
and I want t
let view = ...
let point = ...
view.bounds.contains(point)
Use CGRectContainsPoint():
bool CGRectContainsPoint(CGRect rect, CGPoint point);
Parameters
rect
The rectangle to examine.point
The point to examine.
Return Value
true if the rectangle is not null or empty and the point is located within the rectangle; otherwise, false.A point is considered inside the rectangle if its coordinates lie inside the rectangle or on the minimum X or minimum Y edge.
I'm starting to learn how to code with Swift and was trying to solve this too, this is what I came up with on Swift's playground:
// Code
var x = 1
var y = 2
var lowX = 1
var lowY = 1
var highX = 3
var highY = 3
if (x, y) >= (lowX, lowY) && (x, y) <= (highX, highY ) {
print("inside")
} else {
print("not inside")
}
It prints inside