开发者

Building drag and drop interface on iphone

开发者 https://www.devze.com 2023-01-01 16:50 出处:网络
I am trying to build an app which will have a bunch of cards that the user needs to drag and drop them onto开发者_如何学C specific drop zones. How would one go about detecting this and if the card is

I am trying to build an app which will have a bunch of cards that the user needs to drag and drop them onto开发者_如何学C 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?


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

}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消