PageRenderTime 40ms CodeModel.GetById 23ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/samples/MapTestbed/Classes/RootViewController.m

http://github.com/route-me/route-me
Objective C | 113 lines | 74 code | 27 blank | 12 comment | 5 complexity | 33a9137bfd885615abed283299d83492 MD5 | raw file
  1//
  2//  RootViewController.m
  3//  MapTestbed : Diagnostic map
  4//
  5
  6#import "RootViewController.h"
  7#import "MainViewController.h"
  8#import "FlipsideViewController.h"
  9
 10
 11@implementation RootViewController
 12
 13@synthesize infoButton;
 14@synthesize flipsideNavigationBar;
 15@synthesize mainViewController;
 16@synthesize flipsideViewController;
 17
 18
 19- (void)viewDidLoad {
 20    
 21    [super viewDidLoad];
 22    MainViewController *viewController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
 23    self.mainViewController = viewController;
 24    [viewController release];
 25    
 26    [self.view insertSubview:mainViewController.view belowSubview:infoButton];
 27}
 28
 29
 30- (void)loadFlipsideViewController {
 31    
 32    FlipsideViewController *viewController = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
 33    self.flipsideViewController = viewController;
 34    [viewController release];
 35    
 36    // Set up the navigation bar
 37    UINavigationBar *aNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
 38    aNavigationBar.barStyle = UIBarStyleBlackOpaque;
 39    self.flipsideNavigationBar = aNavigationBar;
 40    [aNavigationBar release];
 41    
 42    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(toggleView)];
 43    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"MapTestbed"];
 44    navigationItem.rightBarButtonItem = buttonItem;
 45    [flipsideNavigationBar pushNavigationItem:navigationItem animated:NO];
 46    [navigationItem release];
 47    [buttonItem release];
 48}
 49
 50
 51- (IBAction)toggleView {    
 52    /*
 53     This method is called when the info or Done button is pressed.
 54     It flips the displayed view from the main view to the flipside view and vice-versa.
 55     */
 56    if (flipsideViewController == nil) {
 57        [self loadFlipsideViewController];
 58    }
 59    
 60    UIView *mainView = mainViewController.view;
 61    UIView *flipsideView = flipsideViewController.view;
 62    
 63    [UIView beginAnimations:nil context:NULL];
 64    [UIView setAnimationDuration:1];
 65    [UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES];
 66    
 67    if ([mainView superview] != nil) {
 68        [flipsideViewController viewWillAppear:YES];
 69        [mainViewController viewWillDisappear:YES];
 70        [mainView removeFromSuperview];
 71        [infoButton removeFromSuperview];
 72        [self.view addSubview:flipsideView];
 73        [self.view insertSubview:flipsideNavigationBar aboveSubview:flipsideView];
 74        [mainViewController viewDidDisappear:YES];
 75        [flipsideViewController viewDidAppear:YES];
 76
 77    } else {
 78        [mainViewController viewWillAppear:YES];
 79        [flipsideViewController viewWillDisappear:YES];
 80        [flipsideView removeFromSuperview];
 81        [flipsideNavigationBar removeFromSuperview];
 82        [self.view addSubview:mainView];
 83        [self.view insertSubview:infoButton aboveSubview:mainViewController.view];
 84        [flipsideViewController viewDidDisappear:YES];
 85        [mainViewController viewDidAppear:YES];
 86    }
 87    [UIView commitAnimations];
 88}
 89
 90
 91// Override to allow orientations other than the default portrait orientation.
 92- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 93	// Return YES for supported orientations
 94	return YES;
 95}
 96
 97
 98- (void)didReceiveMemoryWarning {
 99    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
100    // Release anything that's not essential, such as cached data
101}
102
103
104- (void)dealloc {
105    [infoButton release];
106    [flipsideNavigationBar release];
107    [mainViewController release];
108    [flipsideViewController release];
109    [super dealloc];
110}
111
112
113@end