Obaid
Obaid

Reputation: 4358

Building drag and drop interface on iphone

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

Answers (2)

P.O
P.O

Reputation: 301

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

Upvotes: 2

nickthedude
nickthedude

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

Related Questions