Building drag and drop interface on iphone

时光毁灭记忆、已成空白 提交于 2020-01-02 23:12:13

问题


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:


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

}



回答2:


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



来源:https://stackoverflow.com/questions/2955629/building-drag-and-drop-interface-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!