Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Presenting a view controller with transparency and animation

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.

like image 237
Peter Warbo Avatar asked Apr 03 '13 15:04

Peter Warbo


People also ask

How do I create a transition animation for a view controller?

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.

What is presenting a view controller?

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.

How are transitions called in the camera view controller?

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:).

How to animate a from view controller in a container?

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.


1 Answers

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;
like image 191
Peter Warbo Avatar answered Sep 18 '22 10:09

Peter Warbo