2 // LBAlgorithmAnimationViewController.m
5 // Created by Mike Mayo on 6/2/11.
6 // Copyright 2011 __MyCompanyName__. All rights reserved.
9 #import "LBAlgorithmAnimationViewController.h"
12 @implementation LBAlgorithmAnimationViewController
14 @synthesize algorithm, imageView, navigationBar;
16 - (id)initWithAlgorithm:(NSString *)a {
17 self = [super initWithNibName:@"LBAlgorithmAnimationViewController" bundle:nil];
27 [navigationBar release];
31 #pragma mark - View lifecycle
33 - (void)loadAnimation {
34 NSInteger imageCount = 0;
35 NSString *abbreviation = @"";
37 if ([algorithm isEqualToString:@"Round Robin"]) {
40 } else if ([algorithm isEqualToString:@"Weighted Round Robin"]) {
42 abbreviation = @"wrr";
43 } else if ([algorithm isEqualToString:@"Weighted Least Connections"]) {
45 abbreviation = @"wlc";
46 } else if ([algorithm isEqualToString:@"Random"]) {
48 abbreviation = @"random";
49 } else if ([algorithm isEqualToString:@"Least Connections"]) {
54 NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:imageCount];
55 for (int i = 1; i < imageCount + 1; i++) {
56 NSString *filename = [NSString stringWithFormat:@"%@-%02d_s%02d.png", abbreviation, i, i];
57 [images addObject:[UIImage imageNamed:filename]];
59 self.imageView.animationImages = [NSArray arrayWithArray:images];
60 self.imageView.animationRepeatCount = 0;
61 self.imageView.animationDuration = imageCount * .4;
62 [self.imageView startAnimating];
69 self.navigationBar.topItem.title = self.algorithm;
73 - (void)viewDidUnload {
74 [super viewDidUnload];
76 self.navigationBar = nil;
79 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
80 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
83 return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
87 #pragma mark - Button Handlers
89 - (IBAction)doneButtonPressed:(id)sender {
90 [self dismissModalViewControllerAnimated:YES];