7

in iOS 7 there is no problem for this method:

_rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[_rootViewController presentViewController:self animated:NO completion:nil];

But in iOS 8 it did nothing.How to solve it? Is it a Bug for iOS 8?

SuperHappy
  • 161
  • 2
  • 11

2 Answers2

13

My answer is more simple, below code. This works in iOS8 (XCode6 GM seed).

HogeViewController *vc = [[HogeViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:vc animated:NO completion:nil];
ushisantoasobu
  • 211
  • 2
  • 5
  • 1
    if you rotation your app in the vc view what happened? In my app it rotate when the method - (BOOL)shouldAutorotate { return NO; } – SuperHappy Sep 12 '14 at 03:51
  • Beware. If you are using an unwind segue, you may need to explicitly call dismissViewController in your unwind segue handler to make the view disappear. – jlukanta Dec 03 '14 at 07:58
3

Note this workaround was needed on xcode6_beta7. The lastest xcode6 has the UIModalPresentationOver* styles fixed. So, I'm just assigning them to myModalViewController.modalPresentationStyle and now it works ok.

Finally made it work in iOS 8 after reading the UIPresentationController help and this post

appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
MyModalController *myModalController = [[MyModalController alloc] initWithNibName:@"MyModalController" bundle:nil];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myModalController];
navController.modalPresentationStyle = UIModalPresentationCustom;
navController.transitioningDelegate = myModalController;

[self.navigationController presentViewController:navController animated:YES completion:nil];

You can make the modal view controller inherit from UIViewControllerTransitioningDelegate

@interface MyModalController : UIViewController <UIViewControllerTransitioningDelegate>

and override presentationControllerForPresentedViewController:...

-(UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source
{
    if (presented == self) {
        return [[TransparentPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
    } else {
        return nil;
    }
}

returning an instance of TransparentPresentationController which inherits from UIPresentationController

@interface TransparentPresentationController : UIPresentationController

and overrides shouldRemovePresentersView

- (BOOL) shouldRemovePresentersView {
    return NO;
}
Zuzel Vera
  • 51
  • 4
  • I write this in another sence: – SuperHappy Sep 09 '14 at 06:23
  • I write this in two scenes: In ViewController: - (IBAction)present:(id)sender { //scene two SecondViewController *controller = [[SecondViewController alloc] init]; [controller present]; } For sence two:-(void)present { UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; [self setTransitioningDelegate:self.transitionController]; self.modalPresentationStyle= UIModalPresentationCustom; [root presentViewController:self animated:YES completion:nil]; } But it did not do the delegate method.Why?yours is right. – SuperHappy Sep 09 '14 at 06:29
  • I overrode shouldRemovePresentersView to return NO. But I still cannot access the presenters view. the viewForKey returns nil – Shirish Kumar May 19 '15 at 19:01