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

iPhone

开发平台:

MultiPlatform

  1. //
  2. //  SwitchViewController.m
  3. //  View Switcher
  4. //
  5. //  Created by Jeff LaMarche on 7/6/08.
  6. //  Copyright 2008 __MyCompanyName__. All rights reserved.
  7. //
  8. #import "SwitchViewController.h"
  9. #import "BlueViewController.h"
  10. #import "YellowViewController.h"
  11. @implementation SwitchViewController
  12. @synthesize blueViewController;
  13. @synthesize yellowViewController;
  14. - (void)viewDidLoad
  15. {
  16. BlueViewController *blueController = [[BlueViewController alloc] initWithNibName:@"BlueView" bundle:nil];
  17. self.blueViewController = blueController;
  18. [self.view insertSubview:blueController.view atIndex:0];
  19. [blueController release];
  20. }
  21. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  22. if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
  23. // Initialization code
  24. }
  25. return self;
  26. }
  27. - (IBAction)switchViews:(id)sender
  28. {
  29. if (self.yellowViewController == nil)
  30. {
  31. YellowViewController *yellowController = [[YellowViewController alloc] 
  32.   initWithNibName:@"YellowView" bundle:nil];
  33. self.yellowViewController = yellowController;
  34. [yellowController release];
  35. }
  36. [UIView beginAnimations:@"View Flip" context:nil];
  37. [UIView setAnimationDuration:1.25];
  38. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  39. UIViewController *coming = nil;
  40. UIViewController *going = nil;
  41. UIViewAnimationTransition transition;
  42. if (self.blueViewController.view.superview == nil) 
  43. {
  44. coming = blueViewController;
  45. going = yellowViewController;
  46. transition = UIViewAnimationTransitionFlipFromLeft;
  47. }
  48. else
  49. {
  50. coming = yellowViewController;
  51. going = blueViewController;
  52. transition = UIViewAnimationTransitionFlipFromRight;
  53. }
  54. [UIView setAnimationTransition: transition forView:self.view cache:YES];
  55. [coming viewWillAppear:YES];
  56. [going viewWillDisappear:YES];
  57. [going.view removeFromSuperview];
  58. [self.view insertSubview: coming.view atIndex:0];
  59. [going viewDidDisappear:YES];
  60. [coming viewDidAppear:YES];
  61. [UIView commitAnimations];
  62. }
  63. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  64. // Return YES for supported orientations
  65. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  66. }
  67. - (void)didReceiveMemoryWarning {
  68. [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
  69. // Release anything that's not essential, such as cached data
  70. }
  71. - (void)dealloc {
  72. [yellowViewController release];
  73. [blueViewController release];
  74. [super dealloc];
  75. }
  76. @end