2

I´m trying to animate a sort of draggable UIView where the behaviour should be something like this:

  • Drag along the screen following the touch of the user.
  • Detect a swipe touch and drag automatically with an initial speed and a negative acceleration that makes is stop after some time.

Something like moving around a photo and then through it to one side of the screen.

Any tips on this?

asked Jul 16, 2009 at 15:06

nico's user avatar

5

A similar question was asked (by me) about 3 weeks ago. Though some of the answers I received were a little off the mark the best advice was: 1- study Apple's MoveMe example for how to touch an object and drag it around. And 2- you "throw" the object by basically comparing the [touch locationInView:self.view] to the [touch previousLocationInView:self.view] in touchesEnded (could also store a reference to first touch in touchesBegan but I find that less helpful as user may pause) using the time stamp of each you can determine the direction of swipe (flick) and rate of speed and use them to send your little UIView flying around. Obviously you want to apply forces ("friction") or whatever to slow it down so it doesn't fly right of your screen...

Community's user avatar

answered Jul 16, 2009 at 15:59

Meltemi's user avatar

2 Comments

thanks. How do I apply those "friction" forces? should I use a CAKeyframeAnimation with different timings? How do I generate this timings? I´m kind of lost in the world of animations.

0

I am not sure. But may be you can use decelerating property of UIScrollView object. Put your imageView in UIScrollView and use this property. Its a BOOL var and the returned value is YES if user isn't dragging the content but scrolling is still occurring.

answered Jul 16, 2009 at 15:15

AJ.'s user avatar

AJ.

1,4637 gold badges19 silver badges31 bronze badges

1 Comment

sorry, not what im looking for

0

Take a look at the MoveMe sample project from Apple (registration may be required). It demonstrates how to have a placard follow a touch as well as transform itself based on different touches.

Essentially, the idea is that you override the UIResponder touch methods to analyze what kind of touch the device received, and then either move the object to follow the user's finger or give it a speed in a direction depending on whether it was a slow drag or a swipe. You can then use Core Animation to animate changes to the object's frame.

answered Jul 16, 2009 at 15:19

Tim's user avatar

Tim

60.3k19 gold badges159 silver badges165 bronze badges

1 Comment

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.