views:

948

answers:

6

I've got some UIViews that I'd like the user to be able to "flick" across the screen. They're not scroll views. They simply contain a raster image (png). Can anyone point me to some sample code, etc to help get me started? Something a little more heavyweight than "MoveMe" out there that helps detect a "flick" (vs a "nudge" or a drag and drop) and then carries the view off in the direction of the "flick"?

OpenGL probably overkill. If possible I'd like to stay w/in the realm of Core Graphics/Animation.

A: 

Suppose you have an UIView called aView and two UIImageViews, page1 and page2. Supposing you have page1 already as a subview in aView, this code will flip from page1 to page2:

[UIView beginAnimations:@"someId" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:aView cahe:YES];
[page1 removeFromSuperview];
[aView addSubview:page2];
[UIView commitAnimations];
Marco Mustapic
I'm not transitioning between "pages" per say. More like trying to toss images from one side of screen to the other.
Meltemi
A: 

To detect the touch, in a view controller, you could use the touchesBegan and touchesEnded methods, store the touch from touchesBegan, and if the touch moved more than some amount to the left or right, it was a flick, not a nudge to the left or right.

nazgul42
yes, but that wouldn't distinguish a drag necessarily from a flick. perhaps I should have been more specific. someone "picking something up" and "dropping" it needs to be handled differently from someone "flicking" (throwing) it.
Meltemi
What is the difference between a "pick something up" and "drop" it and flicking something?
nazgul42
Meltemi
+1  A: 

I would say that the easyeist way to implement this would be to put your views in an UIScrollView container with paging enabled and let it worry about all the "flicking" actions. Works great for me.

You can even with some additional effort have views lazy load the images.

Ron Srebro
Meltemi
+1  A: 

I guess you could achieve this easily by taking the nazgul42 answer and checking also the time between the two mentioned events. Short time and long distance combined could be then interpreted as flick. Also you can determine the direction of the flick by calculating the coordinates both touch event points.

A: 

I'm looking for the same information. Did you ever get this to work? Or, find an answer?

Susannah
A: 

I found a thread here, although the method worries me -

http://discussions.apple.com/message.jspa?messageID=7862186

It doesn't take speed or timestamps into account; just the distance since the last event update. If Apple ever changed the freqency/granularity of event updates, this code could break.

smasher