4

I'm building my app using storyboard.so I can open another view controller when button preesed,by dragging.and then I can select presentation= over current context for the segue in storyboard.But what I want is to do this programmatically.I found an answer,but it says it will work for only ipads.I'm building an universal app, so I want to work it for all devices.

  • Is this possible.
  • And how can I do that.

in my first view controller

UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *middleViewController = [story instantiateViewControllerWithIdentifier:@"FlightMiddleViewController"];

and in my second view controller, viewDidLoad method I put

self.modalPresentationStyle = UIModalPresentationOverCurrentContext;

it works for a while.that means it transparent for while and then screen black.I don't know why is that.

caldera.sac
  • 4,918
  • 7
  • 37
  • 69

4 Answers4

10

it is working for iphone also with ios 9 >=

this is what you want to do.

in your first view controller, before you set up which view should present,

- (IBAction)searchNowAction:(id)sender {

    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    UIViewController *secondViewController = [story instantiateViewControllerWithIdentifier:@"secondviewControllerSBname"];


    secondViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
    secondViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentViewController:secondViewController animated:YES completion:nil];

}

this works fine for iphones also.

caldera.sac
  • 4,918
  • 7
  • 37
  • 69
3

You need to set following property before presenting.

self.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext

Also set definesPresentationContext property of parent controller to true

Yes it will work only for iPad, as modal presentations and popover controllers are only supported in iPad.

Vishnu gondlekar
  • 3,896
  • 21
  • 35
0

Actually, it's not that hard to do OverCurrentContext presentation style on iPhone. Have a look at UIViewController custom transition, which was introduced in iOS 7. You will find out how to do it.

Eric Qian
  • 2,246
  • 1
  • 18
  • 15
0

For anyone that was doning performSegue(.. programmatically

In my case I was having a modal that present a button. taping the button should push a new viewController, but it get push in fullScreen even if Im inside a modal

So after little search I found out that I was setting in storyBoard in xcode: Presentation => fullScreen. So then I had to change is to Current Context

Siempay
  • 876
  • 1
  • 11
  • 32