PageRenderTime 23ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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