Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have UINavigationController use flip animation while push a UIViewController

Now I have four UITableViewControllers.

  • A
  • B1, B2
  • C

I need the following effect:

  • Select an item on A can push to B1
  • Tap the rightBarButtonItem on B1 can flip horizontal to B2
  • Tap the rightBarButtonItem on B2 can flip horizontal to B1
  • Select an item on B1 or B2 can push to C
  • Can pop to A at B1 or B2

All views (A, B1, B2 and C) should have NavigationBar.

Now I can navigate between A, B1, B2, C. I can also flip to B2 using the following code:

//self is B1
- (IBAction)b2ButtonPressed
{
    B2ViewController* B2 = [[B2ViewController alloc] init];
    B2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

    [self presentModalViewController:B2 animated:YES];
}

But on B2 the NavigationBar is missing.

I have an app on my iPod touch has such feature. How can I make it myself?

like image 524
Zhao Xiang Avatar asked Jun 19 '11 13:06

Zhao Xiang


1 Answers

If you show the view controllers by modal presenting, not by navigation controller's push or pop, you should wrap a navigation controller for the view controller in order to show the navigation bar:

- (IBAction)b2ButtonPressed
{
  B2ViewController* B2 = [[B2ViewController alloc] init];
  UINavigationController *B2Nav = [[UINavigationController alloc] initWithRootViewController:B2];   
  B2Nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
  [self presentModalViewController:B2Nav animated:YES];
  [B2 release];
  [B2Nav release];
}

And don't forget to setup left or right bar button item for navigation bar in your B2ViewController.

like image 137
cxa Avatar answered Oct 02 '22 23:10

cxa