I am creating a fairly simple app with several draggable images in a view, and I want a reset button which will reset all the images to their original positions. Can anyone help with the code for this, or point me to some useful resources?
Hi there,
Excellent, i got it working now. I have just one other issue i am unable to solve so far; when i grab an image to drag it, as soon as i start moving it the image jumps so that it's centre moves to the cursor [on my IOS Simulator]. The drag action still works, it just looks a bit sloppy, or jumpy, instead of smooth. Any ideas?
Thanks architectpianist, but i can't get that code to work; the image can be dragged, but it still jumps when i begin dragging it.
scruffy
I would suggest not moving the image location to the point the user touches, but instead, detecting a dragging motion, and offsetting the image location by the amount the user drags.
UIGestureRecognizers make this much easier. Do a search in Xcode on "touches" and download the sample app with that name. That will get you 2 projects, one that does it the old way, with touchesBegan/touchesMoved, and the other that uses gesture recognizers. Take a look at the gesture recognizer one.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Hi Guys,
Thanks for your help. I have followed all advice and tried out all the above suggestions but unfortunately i don't know enough to make any of them work. However i found an example by Navaneethan Thambu called MyDragApp which i can get to work so i will follow that trail for the moment. It uses the older method but it works and as a novice at this thats all i can go by atm.
Hi Duncan,
Regarding the Touches app that you recommended, i have found some of the things i need in an app, using UIGestureRecognizers, but i cannot set Touches into landscape mode. I can make it turn to the right, but the images move 90 degrees as well. I have spent some days on this, exploring lots of image movement apps trying to find one that does all the things i need it to do and i have found all the elements i need, but not all in the one app. Anyway, thanks for your help.
Quote:
Originally Posted by Duncan C
I would suggest not moving the image location to the point the user touches, but instead, detecting a dragging motion, and offsetting the image location by the amount the user drags.
UIGestureRecognizers make this much easier. Do a search in Xcode on "touches" and download the sample app with that name. That will get you 2 projects, one that does it the old way, with touchesBegan/touchesMoved, and the other that uses gesture recognizers. Take a look at the gesture recognizer one.
Hi Duncan,
Regarding the Touches app that you recommended, i have found some of the things i need in an app, using UIGestureRecognizers, but i cannot set Touches into landscape mode. I can make it turn to the right, but the images move 90 degrees as well. I have spent some days on this, exploring lots of image movement apps trying to find one that does all the things i need it to do and i have found all the elements i need, but not all in the one app. Anyway, thanks for your help.
Dragging with gesture recognizers has very little to do with auto-rotation. Auto-rotation is a separate issue. If you find one example of how to do it, it's a simple matter to adapt the technique to most applications.
You're unlikely to find a single sample app that does exactly what you want. You need to be able to use samples to learn new techniques, and then adapt and synthesize those techniques into new applications.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Dragging with gesture recognizers has very little to do with auto-rotation. Auto-rotation is a separate issue. If you find one example of how to do it, it's a simple matter to adapt the technique to most applications.
You're unlikely to find a single sample app that does exactly what you want. You need to be able to use samples to learn new techniques, and then adapt and synthesize those techniques into new applications.
Touches is a dirt-simple application. It doesn't even have a view controller. (I'm a little surprised the system doesn't complain about that. Newer OS versions expect your app to create a view controller on launch.)
The method shouldAutorotateToInterfaceOrientation is a view controller method.
If you create an app with a view controller, and add your shouldAutorotateToInterfaceOrientation method above, then it should allow the UI to rotate to all user interface orientations. You then need set up the "struts and springs" (resize controls) in your views so that they resize as the window size changes. For most apps, that's all there is to it.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Finally got it, thanks to a lot of help and a tutorial. Added Pan Gesture Recognizers from the objects library to the image containers on the storyboard, added some code and hooked it up and it works!
Then you select the UIPanGestureRecongizer in Interface Builder, bring up the Connections inspector, and drag a line from the selector to the View Controller, and choose handlePan and thats it.
Now everything works smoothly, and it rotates too
Thanks again
Scruffy
Quote:
Originally Posted by Duncan C
Touches is a dirt-simple application. It doesn't even have a view controller. (I'm a little surprised the system doesn't complain about that. Newer OS versions expect your app to create a view controller on launch.)
The method shouldAutorotateToInterfaceOrientation is a view controller method.
If you create an app with a view controller, and add your shouldAutorotateToInterfaceOrientation method above, then it should allow the UI to rotate to all user interface orientations. You then need set up the "struts and springs" (resize controls) in your views so that they resize as the window size changes. For most apps, that's all there is to it.
So, I am using this same code but, getting some very odd reactions. When I pan up down, the view moves left and right. When I pan left/right, the view moves up and down. If I change the code (flip the x and y's) to below, it at least works up down but, then the pan left move it right and the pan right moves it left.
I am dropping the action on the 'whole' view. IE: not just an image view but attaching it to the main view by highlighting the outside of the outline in the .xib file.
Anyone encounter anything strange like this? Happens on both the simulator and the iPad.
Finally got it, thanks to a lot of help and a tutorial. Added Pan Gesture Recognizers from the objects library to the image containers on the storyboard, added some code and hooked it up and it works!
Then you select the UIPanGestureRecongizer in Interface Builder, bring up the Connections inspector, and drag a line from the selector to the View Controller, and choose handlePan and thats it.
Now everything works smoothly, and it rotates too