Presenting the ViewController in full screen - ios

I am presenting a view controller in a button action as follows,
PromptController *obj = [[[PromptController alloc]initWithNibName:#"PromptController" bundle:nil]autorelease];
UINavigationController *navigation = [[[UINavigationController alloc]initWithRootViewController:obj]autorelease];
[self presentViewController:navigation animated:YES completion:nil];
[AVSession stopRunning];
But it is not presenting on the full screen of the phone. It is presenting as follows
How to present it on the full screen. Any help is really appreciated

In iOS 13 the default presentation style has changed. If you want iOS 12 presentation style, you can change the modalPresentationStyle to .fullScreen.
Swift Version
navigation.modalPresentationStyle = .fullScreen
Objective C
navigation.modalPresentationStyle = UIModalPresentationOverFullScreen;

Related

Present a blurred UIViewController on top of another UIViewController

I have 2 VCs - firstVC and secondVC.
secondVC's view's color is clear color and it has a UIVisualEffect view with dark blur.
I want to present secondVC modally on firstVC but when I do that, firstVC becomes black.
Thank you
You need to set the modalPresentationStyle appropriately on the presented (secondVC) controller.
UIModalPresentationOverFullScreen or UIModalPresentationOverCurrentContext will provide the effect of the second VC's content over the top of the first VC.
if ios version >= 8.0 then
SecondViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:SecondViewController animated:YES completion:nil];
if using ios7 & navigation controller then
self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:SecondViewController animated:YES completion:nil];
if there is no navigation controller then
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:SecondViewController animated:YES completion:nil];

Black Screen After Dismissing Modal Controller

I've discovered that after dismissing a modal view controller that's presented fullscreen in a compact view and as a popover in a horizontally regular view, the screen goes black after the animation.
My View Hierarchy is the following
View (of my rootViewController on the window)
--->UISplitViewController.view ( set as a child viewController )
--------> rootViewController.view (set as the mainViewController of the splitView)
--------> detailViewController.view (set as the detailViewController of the split view)
Via the iPhone 6 simulator(split view is always collapsed) I present a modal viewcontroller with the following code:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[navigationController.navigationBar setBarStyle:UIBarStyleBlack];
[navigationController setModalPresentationStyle:UIModalPresentationPopover];
navigationController.popoverPresentationController.sourceView = view;
navigationController.popoverPresentationController.barButtonItem = barButtonItem;
navigationController.popoverPresentationController.delegate = self;
[self presentViewController:nav animated:YES completion:nil];
I dissmiss the presented controller from that viewController by calling:
[self dismissViewControllerAnimated:true completion:nil];
If I set animated to "false" I dont have any problems, but it looks bad and doesnt make sense.
I see some posts regarding this and custom presenatation methods, but I'm not using anything custom here.
On iPhone the ModalPresentationStyle should default to UIModalPresentationOverFullScreen, so I tried setting the presentationStyle directly to that, and it worked!
If I set the presentationStyle to "FullScreen" (not over fullscreen) I get the same behavior, a black screen after dismissing.
Any thoughts or experiences on this one?
I've come up with the following work around, but I still don't think it should be needed.
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection{
if( traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact )
{
return UIModalPresentationOverFullScreen;
}
else
{
return UIModalPresentationPopover;
}
}

viewWillAppear incorrect orientation when presentViewController without a navigation view controller

I came across a strange problem, i'am in landscape and present a VC
SomeViewController * vc = [[SomeViewController alloc] init];
[self.navigationController presentViewController:vc animated:YES completion:^{
}];
in the viewWillAppear the frame is incorrectly in portrait and in viewDidAppear it is correctly in landscape
but when i put it inside a UINavigationController
SomeViewController * vc = [[SomeViewController alloc] init];
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:vc];
[self.navigationController presentViewController:nc animated:YES completion:^{
}];
than in the viewWillAppear the frame is correctly landscape
Is this a bug? I'am i missing something? Why it is behaving like this?
I think it is by design, see this answer A: View frame changes between viewWillAppear: and viewDidAppear:.
By viewDidAppear the frame geometry is correct since it is now on-screen and added to the view hierarchy but I would actually recommend doing it in viewDidLayoutSubviews since that will be called when rotating orientations as well.

Switching underlaying view controllers iOS 8

This is the goal :
I have a navigation controller (NC1), that is presenting modally some view controller (VC). When I do some action in that view controller, I need to (invisibly for the user) dismiss VC, dismiss NC1, then present another navigation controller (NC2) and present the same view controller VC.
In iOS 7.0, 7.1 this is working well via this (slightly adjusted) code:
[controller dismissViewControllerAnimated:NO completion:nil]; //dismiss VC
[self.presentedViewController dismissViewControllerAnimated:NO completion:nil]; //dismiss NC1
SomeViewController * someViewController = [[SomeViewController alloc] init]; // root vc for NC2
NavigationController * navigationController = [[NavigationController alloc] initWithRootViewController:someViewController]; //NC2
SomeViewController2 * someViewController2 = [[SomeViewController2 alloc] init];
[navigationController presentSomehow:someViewController2 animated:NO completion:nil]; //another pushed to NC2
[someViewController2 presentViewController:controller animated:NO completion:nil]; //present VC again
but in iOS 8 (Xcode 6.0) it seems that even after dismissing, VC remains active and the app crashes at the last line with:
Application tried to present modally an active controller ...
And of course if I move the code to completion blocks the changes are visible to user (and ugly).
Is there a way to check or force the VC to leave the active state, or some other way to simulate the iOS 7 behavior?
Thanks for answers!

UINavigationController clear background color

That simple example but that don't work;
I have ViewController where inside on NavigationConroller, then I want to add new ViewConroller with its self navigation controller.
In main viewController:
CustomViewController *vc = [[CustomViewController alloc] init];
NewNavigationVC *nav = [[NewNavigationVC alloc] initWithRootViewController:vc];
[self presentViewController:nav animated:NO completion:nil];
Two controllers has a background color clear, but still black color.
Navigation bar I can do clear, but not a view.
UPDATE:
if i change self.window.backroundColor to red for example, that work but not clear
UPDATE 2:
[self addChildViewController:vc];
[self.view addSubview:vc.view];
[vc didMoveToParentViewController:self];
and when I want to dealloc vc
[vc willMoveToParentViewController:nil];
[vc.view removeFromSuperview];
[vc removeFromParentViewController];
All work ok without navigation controller
A viewController's view's backgroundColor can't be clear (as in showing the previous viewController's view on the stack). Pushing or presenting a viewController will put the new viewController on the stack and hide the previous viewController completely.
If you want a clear backgroundColor on the view, you will need to either:
1) set the viewController as a childViewController of the previous viewController - then animate the transition yourself.
Or
2) transplant the viewController logic into the previous viewController and have a new uiview act as that view (you also need to animated the transition yourself).
The solution is as follows. For clear example we use tableViewController:
UITableViewController *modalVC = [UITableViewController new];
UINavigationController *modalNVC = [[UINavigationController alloc] initWithRootViewController:modalVC];
UIViewController *mainVC = [UIViewController new];
UINavigationController *mainNVC = [[UINavigationController alloc] initWithRootViewController:mainVC];
modalVC.view.backgroundColor = UIColor.clearColor;
mainVC.view.backgroundColor = UIColor.redColor;
mainNVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[mainNVC presentViewController:modalNVC animated:YES completion:NULL];
The key feature is that you have to set modalPresentationStyle of presentingViewController to UIModalPresentationCurrentContext.
It works fine BUT without slide animation. You will get result immediately.
But you can still use "blood hack" to retain visual animation by successive presenting, dismissing and presenting again:
modalVC.view.backgroundColor = UIColor.clearColor;
mainVC.view.backgroundColor = UIColor.redColor;
[mainNVC presentViewController:modalNVC animated:YES completion:^{
[modalNVC dismissViewControllerAnimated:NO completion:^{
mainNVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[mainNVC presentViewController:modalNVC animated:NO completion:NULL];
}];
}];
You basically need to tell the navigation controller to:
navigation.modalPresentationStyle = .overCurrentContext
In other words:
A presentation style where the content is displayed over another view controller’s content.
and that's it.
You can also make sure that:
navigation.view.backgroundColor = .clear

Resources