I'm setting self.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
in my Application Delegate so that I can present a view controller and have the view be transparent (see this SO question).
This works great, only remark is that I'm not able to animate when the view controller is presented. Has anyone gotten this to work? If not, what other options do I have?
The view controller I'm presenting is a "walkthrough" that consists of a UIScrollView
and UIPageControl
that is supposed to "hover" over the interface so you can see the background of it slightly at the edges.
When view controller B is dismissed, the animation reverses so that B slides down to reveal A. You can create custom transitions using an animator object and transitioning delegate. The animator object creates the transition animations for placing the view controller onscreen.
Presenting a view controller is a quick and easy way to animate new content onto the screen. The presentation machinery built into UIKit lets you display a new view controller using built-in or custom animations.
Marin Todorov wrote the original. Whether you’re presenting the camera view controller or one of your own custom-designed modal screens, it’s important to understand how these transitions are happening. Transitions are always called with the same UIKit method: present (_:animated:completion:).
Here, we create a snapshot of the from view controller ‘s view, add it to the container and remove the from view from the container. We then shrink this snapshot in our animation and when the animation completes, we remove the snapshot view from the container. Run it and the animation should now run smoothly.
I ended up doing this:
AppDelegate *appDelegate = [AppDelegate sharedAppDelegate];
// Set the root VC modal presentation style
appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
WalkthroughViewController *walkthroughVC = [[WalkthroughViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:walkthroughVC animated:NO completion:nil];
// Manually animate the view
walkthroughVC.view.alpha = 0;
[UIView animateWithDuration:0.5 animations:^{
walkthroughVC.view.alpha = 1;
}];
// Reset root VC modal presentation style
appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With