I wrote something similar for my Beat program, but my case, I think, is a bit more complicated, because I rotate in 3D: https://itunes.apple.com/ua/app/bit/id366236469?mt=8
Basically, I create NSTimer, which calls some method regularly. I just take the direction and speed to create a rotation matrix (as I said, 3D is a little nastier: P), and I multiply the speed with some number less than 1, so it drops. The reason for multiplying instead of subtracting is because you donโt want the object to rotate twice as long if the rotation from the user is twice as large, as it becomes annoying to wait for me to find.
To find out in which direction the wheel is spinning, just save it in the toucedEnded: withEvent: methods where you have all the information. Since you are saying that you already have tracking while the user has a thumbs down, this should be obvious.
What I have in 3D is something like:
// MyView.h @interface MyView : UIView { NSTimer *animationTimer; } - (void) startAnimation; @end // MyAppDelegate.h @implementation MyAppDelegate - (void) applicationDidFinishLaunching:(UIApplication *)application { [myView startAnimation]; } @end // MyView.m GLfloat rotationMomentum = 0; GLfloat rotationDeltaX = 0.0f; GLfloat rotationDeltaY = 0.0f; @implementation MyView - (void)startAnimation { animationTimer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)((1.0 / 60.0) * animationFrameInterval) target:self selector:@selector(drawView:) userInfo:nil repeats:TRUE]; } - (void) drawView:(id)sender { addRotationByDegree(rotationMomentum); rotationMomentum /= 1.05; if (rotationMomentum < 0.1) rotationMomentum = 0.1; // never stop rotating completely [renderer render]; } - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { } - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { UITouch *aTouch = [touches anyObject]; CGPoint loc = [aTouch locationInView:self]; CGPoint prevloc = [aTouch previousLocationInView:self]; rotationDeltaX = loc.x - prevloc.x; rotationDeltaY = loc.y - prevloc.y; GLfloat distance = sqrt(rotationDeltaX*rotationDeltaX+rotationDeltaY*rotationDeltaY)/4; rotationMomentum = distance; addRotationByDegree(distance); self->moved = TRUE; } - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { } - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event { }
I did not take into account the addRotationByDegree function, but it uses the rotationDeltaX and rotationDeltaY global variables and applies the rotation matrix to the already saved matrix, and then saves the result. In your example, you probably want something much simpler, for example (I assume that only movements in the X direction rotate the wheel):
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { UITouch *aTouch = [touches anyObject]; CGPoint loc = [aTouch locationInView:self]; CGPoint prevloc = [aTouch previousLocationInView:self]; GLfloat distance = loc.x - prevloc.x; rotationMomentum = distance; addRotationByDegree(distance); self->moved = TRUE; } void addRotationByDegree(distance) { angleOfWheel += distance;
boxed source share