7

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.

Community
  • 1
  • 1
Peter Warbo
  • 11,136
  • 14
  • 98
  • 193

2 Answers2

9

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;
Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
  • This is useful for me too when I'm calling back from AppDelegate (for example Twitter authentication callback), and presenting transparent view controller. – morph85 Jun 02 '16 at 09:14
0

You could use a containment view that exists in the base view controller. Instead of presenting a modal, animate the positioning of the containment view up to simulate a modal presentation.

For example...

TransparentViewController *viewController = [[TransparentViewController alloc] init];
viewController.view.frame = CGRectMake(0, 480, 320, 480);
self.containmnetView = viewController.view;

To present do this:

[UIView animateWithDuration:0.5f animations:^{
    self.containmentView.frame = CGRectMake(0, 0, 320, 480);
}];

I hope this helps.

Ben M
  • 2,405
  • 1
  • 20
  • 19