Seamlessly transition from one modal look to another without showing a solid background color

I have the following interface for an iPad app:

modal view dialog

When I click the Settings button, I want the dialog to flip over to display the settings dialog.

It works fine for me. But there is a background color displayed when the dailog flips. As you can see:

here

Is there a way to prevent this color block from being visible when flipping dialogs? I would like it to look more smoothly - as if a sheet of paper was turned upside down.

Opinions are essentially as follows:

window

The main view. Install rootViewController in the window

Modal view of the entrance

Thus, the main window and the root controller are configured as follows (in the application 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 configured and displayed in the main view 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: the display of the "Settings" modal view is performed in much the same way as the display of the modal login: "

 - (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]; } 
+4
source share
1 answer

I don't think there is a way to do what you want using modalPresentationStyle. You will need to implement the animation yourself using the 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 that you want to flip is not the content of the modal (controller.view), but the modal frame itself, so experiment with just calling the method above from your settings button and instead of passing the controller .view, replace controller.view. superview, and if that doesn't work, try control.view.superview.superview until the animation looks right.

This will require some tweaking to determine exactly how to do this.

+3
source

Source: https://habr.com/ru/post/1393148/


All Articles