How to implement exchanging items' locations by drag and drop
I am working on a mac application but have ran into a road block. I am trying to create 2 images and make it so they can be dragged and dropped to swap their locations. I am completely lost here so a thorough explanation would be greatly 开发者_开发知识库appreciated! I'm not new to programing but Ive only been working with xCode and objective c for a few months. Thanks in Advance!
The similar way is true for your images. The difference is that you replacing two objects at the same time, so you should create two temporary variables.
- create some
CGRect
variable namedimg1rect
to store a rectangle of 1st image andimg2rect
variable (I think you've got for what) - Drag 1st image onto the 2nd, then place. If dragg'n'drop is successfull (e.g. you could check whether touch coordinate is located on 2nd mage) set
img1rect
as frame for the 2nd image andimg2rect
as frame for the 1st.
If the matter of question is drag'n'drop handling you could find plenty of information using search. For example, chck this out: Basic Drag and Drop in iOS
精彩评论