I have a UIView that a user drags around via setting its center in the touchesMoved: method. When the user lets go, I want the UIView to fall off the screen according to how fast and what direction they were moving it in.
Do I need to somehow create a vector by comparing the UIView‘s last center point to it’s new center point? And subtract a fixed amount to the vector’s y value every so often with a NSTimer?
Yes, you will need to a decent amount of physics in calculating
You will need to use the
touchesMovedmethod along with a timer to track the amount of time for the swipe and also the co-ordinates for the new location of the object. This should be fairly straight forward. Once you are done finding those you can simply add aUIAnimationfor the object to move to its new place.~ A suggestion:
I would suggest that you have a look at
Cocos2Dand integrate the library with you app. You will not need to implementtouch delegatemethods and compute things yourself ~ there are libraries for that 🙂 It has a lot of libraries especially for moving objects (orspritesif you wish to call them that way) and you have animation method likeeaseInEaseOut, etc.. that can be impacted on the moving object. If you are developing a game of some sort, have a look atchipMunkengine in Cocos2D as well.