PDA

View Full Version : Save the position (CGPoints) of a image.




BarryK88
Mar 30, 2011, 08:01 AM
I'm trying to save the positions of several images whom are inside my view. How can i store the coordinates of the images so that when the App launches the images are still at the same location?

Thanks in advance!



robbieduncan
Mar 30, 2011, 08:10 AM
I'd look at saving a NSMutableDictionary to your apps sandboxed area. You can easily store CGPoints as NSNumbers

BarryK88
Mar 30, 2011, 08:14 AM
I'd look at saving a NSMutableDictionary to your apps sandboxed area. You can easily store CGPoints as NSNumbers

Is this function able to get the coordinates by itself. I'm using drag functions on the images inside my view and like to store their coordinates when dragged.

Can you provide me with an example.

Many thanks!

robbieduncan
Mar 30, 2011, 08:41 AM
Can you provide me with an example.

No. I fundamentally believe that it does not help. People just copy and paste without learning anything about the code they are copying or how to help themselves. I have suggested a starting point. Look up those classes in the documentation. Figure out how to use them. Look at the guides in the documentation. Everything you want to do is covered in there.

If you have specific questions about individual methods/functions then post code and I'll try and answer.

xStep
Mar 30, 2011, 03:44 PM
Did something like this just this week. I decided that NSMutableDictionary was overly complicated so I used an NSMutableArray and handled the offset when iterating through the list.

The reason to use NSNumber is because the NS dictionaries and arrays only handle objects, so you need to convert your CGPoints to an an object that is then added to your collection object.