Reputation: 263
I am trying to create a simple simulation app on iPad: On the right hand side there is a key and I have to drag and drop the key into the lock which is at the Bottom-centre of the screen: The key is currently an image and the lock also is an image.
The questions I have:
1) How would I know the key is on top of the lock hence I can make the lock turn Green and key disappear with an animation, if possible ?
2) How to move the key (Like it has detached from the right vertical bar) and when dropped on the lock turns green else stays same?
3) any animation when the lock opens (this is an Addon Query)?
What should my approach be to this kind of simulation?
So far I have image acting as button and onPress is showing some function but I have no idea how to deal with movement and animation/effects.
Please guide me so that I can achieve the above requirement.
Thanks in Advance.
Upvotes: 0
Views: 363
Reputation: 53870
You can use a UIPanGestureRecognizer for the drag gesture. In the action for the recognizer, you can examine the state of the recognizer.
When the gesture is in the begin state, get the current point of the gesture. Then, use hitTest to see if the key image view was under the finger at the beginning of the gesture. If it was, store the origin of the key image so that you can add to it.
Use the properties of the gesture to animate (move) the key image view on consecutive actions.
When the gesture is in the end state, do another hit test to see if you are over the lock.
Upvotes: 1