code_junkie

For iphone development, how to flip a UIImageView?

Nov 13th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. + (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache;
  2.  
  3. UIViewAnimationTransitionFlipFromLeft,
  4. UIViewAnimationTransitionFlipFromRight,
  5.  
  6. CGContextRef context = UIGraphicsGetCurrentContext();
  7.  
  8. [UIView beginAnimations:nil context:context];
  9. [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:yourContainerView cache:YES];
  10. [yourContainerView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
  11. [UIView commitAnimations];
  12.  
  13. - (void)loadFlipsideViewController {
  14.  
  15. FlipsideViewController *viewController = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
  16. self.flipsideViewController = viewController;
  17. [viewController release];
  18.  
  19. // Set up the navigation bar
  20. UINavigationBar *aNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
  21. aNavigationBar.barStyle = UIBarStyleBlackOpaque;
  22. self.flipsideNavigationBar = aNavigationBar;
  23. [aNavigationBar release];
  24.  
  25. UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(toggleView)];
  26. UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"Test123"];
  27. navigationItem.rightBarButtonItem = buttonItem;
  28. [flipsideNavigationBar pushNavigationItem:navigationItem animated:NO];
  29. [navigationItem release];
  30. [buttonItem release];
  31. }
  32.  
  33.  
  34. - (IBAction)toggleView {
  35. /*
  36. This method is called when the info or Done button is pressed.
  37. It flips the displayed view from the main view to the flipside view and vice-versa.
  38. */
  39. if (flipsideViewController == nil) {
  40. [self loadFlipsideViewController];
  41. }
  42.  
  43. UIView *mainView = mainViewController.view;
  44. UIView *flipsideView = flipsideViewController.view;
  45.  
  46. [UIView beginAnimations:nil context:NULL];
  47. [UIView setAnimationDuration:1];
  48. [UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES];
  49.  
  50. if ([mainView superview] != nil) {
  51. [flipsideViewController viewWillAppear:YES];
  52. [mainViewController viewWillDisappear:YES];
  53. [mainView removeFromSuperview];
  54. [infoButton removeFromSuperview];
  55. [self.view addSubview:flipsideView];
  56. [self.view insertSubview:flipsideNavigationBar aboveSubview:flipsideView];
  57. [mainViewController viewDidDisappear:YES];
  58. [flipsideViewController viewDidAppear:YES];
  59.  
  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. }
Add Comment
Please, Sign In to add comment