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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With