PageRenderTime 87ms CodeModel.GetById 47ms app.highlight 36ms RepoModel.GetById 1ms app.codeStats 0ms

/samples/SampleMap/Classes/RootViewController.m

http://github.com/route-me/route-me
Objective C | 116 lines | 72 code | 27 blank | 17 comment | 5 complexity | 79839c52606830d126723915994b51c1 MD5 | raw file
  1//
  2//  RootViewController.m
  3//  SampleMap : 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:@"SampleMap"];
 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/*
 92 // Override to allow orientations other than the default portrait orientation.
 93 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 94 // Return YES for supported orientations
 95 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 96 }
 97 */
 98
 99
100- (void)didReceiveMemoryWarning {
101	RMLog(@"didReceiveMemoryWarning %@", self);
102    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
103    // Release anything that's not essential, such as cached data
104}
105
106
107- (void)dealloc {
108    [infoButton release];
109    [flipsideNavigationBar release];
110    [mainViewController release];
111    [flipsideViewController release];
112    [super dealloc];
113}
114
115
116@end