Search code examples
objective-cioscocoa-touchipadios5

Seamlessly flip from one modal view to another, without showing a solid colour background


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];    
}

Solution

  • 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.