views:

111

answers:

2

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?

+1  A: 

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

}
nickthedude
Can you elaborate please? How would i test against the boundary bounds?
John Stewart
so is this your answer?
nickthedude
Nick, can you tell me how the "send it back from where it came" code would look like? do I need to cache it somewhere?
John Stewart
yeah you would have to store it somewhere. when you got to put in the center don't forget you need to set the x and y points on the same line, usually with a draggedbox.center = cgpointmake(float,float);
nickthedude
A: 

You should look at CGRectContainsRect(draggedBox.frame, droppingBox.frame);