Scroll FlowCover to a specified panel.

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.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s