4

I have the following UI for an iPad app:

modal view dialog

When I click on the Settings button, I want the dialog to horizontally flip to show the settings dialog.

I have this working fine. But, there is a background colour shown when the dailog flips over. As you can see:

here

Is there any way to not have this block of colour be visible as the dialogs flip? I'd like it to look more seamless -- as if it's a sheet of paper flipping over.

The views are essentially this:

Window

Main View. Set to the window's rootViewController

Login modal view

Thus the main window and root controller are setup as follows (in the app delegate class):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.viewController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

The login window is setup and shown in the main view's viewDidAppear:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // Setup and show Login dialog
    LoginViewController* controller = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
    controller.delegate = self;
    controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    controller.modalPresentationStyle = UIModalPresentationFormSheet;
   [self presentModalViewController:controller animated:YES];
}

And when the Settings button is pressed: showing the Settings modal view is done in pretty much the same way that the Login modal view was shown:

- (IBAction)settingsButtonPressed:(id)sender {
    SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];
    controller.delegate = self;
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    controller.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentModalViewController:controller animated:YES];    
}
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Diego Barros
  • 2,071
  • 2
  • 33
  • 45

1 Answers1

3

I don't think there's any way to do what you want using the modalPresentationStyle. You'll need to implement the animation yourself using a transition animation using the following method:

+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion

With the UIViewAnimationOptionTransitionFlipFromLeft option.

In this case the new view you want to flip is not the content of the modal (the controller.view) but the modal frame itself, so experiment with just calling the method above from your settings button, and instead of passing controller.view, substitute controller.view.superview, and if that doesn't work, try controller.view.superview.superview until the animation looks right.

It will require some tweaking to work out exactly how to do it.

Nick Lockwood
  • 40,865
  • 11
  • 112
  • 103
  • 2
    Thanks, Nick. Your suggestion _almost_ worked. The _transitionFromView_ flipped the _Login_ modal dialog to the _Settings_ one; but when _Settings_ was shown, it was fullscreen-sized. So from the smaller sized dialog, to fullscreen. I think this may have to do with the fact that modal views can be told to transition (with my code sample above) in their current context: controller.modalPresentationStyle = UIModalPresentationCurrentContext; – Diego Barros Jan 27 '12 at 04:55