Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate programmatically to another viewcontroller with "over current context " presentation in ios 9, objective C

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.

like image 673
Chanaka Anuradh Caldera Avatar asked Dec 11 '22 18:12

Chanaka Anuradh Caldera


2 Answers

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.

like image 131
Chanaka Anuradh Caldera Avatar answered Dec 13 '22 08:12

Chanaka Anuradh Caldera


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.

like image 34
Vishnu gondlekar Avatar answered Dec 13 '22 07:12

Vishnu gondlekar