I thought for some reason this code was in FlowCover. It’s not, so here it is.
The following routine, if added below -startAnimation: will cause the tiles to scroll to the specified tile, with pos specified from 0 to the max-1 tile.
- (void)runToPos:(int)pos { int max = [self numTiles]-1; if (pos max) pos = max; startOff = offset; startSpeed = sqrt(fabs(pos - startOff) * FRICTION * 2); if (pos < startOff) startSpeed = -startSpeed; runDelta = fabs(startSpeed / FRICTION); startTime = CACurrentMediaTime(); NSLog(@"startSpeed: %lf",startSpeed); NSLog(@"runDelta: %lf",runDelta); timer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(driveAnimation) userInfo:nil repeats:YES]; }
The way this works is to calculate the flick speed necessary to run the animation to the specified position, and runs the animation.