Reputation: 4358
I am trying to build an app which will have a bunch of cards that the user needs to drag and drop them onto specific drop zones. How would one go about detecting this and if the card is not on the drop zone then it should slide back.
Any suggestions on how to structure this app?
Upvotes: 1
Views: 3543
Reputation: 301
You should look at CGRectContainsRect(draggedBox.frame, droppingBox.frame);
Upvotes: 2
Reputation: 4973
View.center test against your boundary bounds. something like this maybe:
if(((draggedBox.center.x >= droppingBox.origin.x) &&
(draggedBox.center.y <= droppingBox.origin.y)) &&
(draggedBox.center.x <= (droppingBox.origin.x + droppingBox.width) &&
(draggedBox.center.y >= (droppingBox.origin.y + droppingBox.height))) {
//do stuff because its inside
}
else {
//send it back from whence it came
draggedBox.center = cgpointmake(originalXposition,originalYposition);
}
Upvotes: 4