tags:

views:

467

answers:

2

I dont know if anyone of you guys know the Spin the Bottle application for the iphone. I want to make a simple app which offers the user a simple image with a bottle. The user should be able to rotate the bottle by using finger gestures. He/She should be able to rotate it with a rotation with the fingers and after releasing (touchesEnd) the bottle should spin further and slow down until it stop at a position based on the speed.

any clues or hints for a solution?

+1  A: 

In order to respond to a custom multi-touch gesture such as a rotation, you'll need to subclass either the image view or the view containing it and build a custom implementation of the following methods:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

Essentially, think of the iPhone screen as a graph, and fingers as points. You use the above methods in a view to figure out how/where fingers are on the graph.

Good starting points:

http://www.iphonesdkarticles.com/2008/09/multi-touch-tutorial.html

http://developer.apple.com/IPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html

http://stackoverflow.com/questions/tagged/multi-touch+iphone

Mark Hammonds
+2  A: 

While it's better if you understand everything yourself, if you want a more concrete example the code here works
Narut's post which is like the 5th response has nice clean code for what you want.

kiyoshi