RootViewController.m
上传用户:jjjjag8
上传日期:2017-04-17
资源大小:1443k
文件大小:4k
源码类别:

iPhone

开发平台:

MultiPlatform

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