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];
Related
I have to present a modal VC under a tabbar. I Have to present it from a tabbar controller
player.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:player animated:YES completion:^{
[self.view bringSubviewToFront:self.tabBar];
}];
That's my code. In this case my model VC covers the tabbar. Is there a way to fix this?
I want to show animation from bottom to top when i am pushing viewController to navigationController?Do any have idea to do it?
RegisterViewController *registerView = (RegisterViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"RegisterViewController"];
Present
[self presentViewController:registerView animated:YES completion:nil];
Dismiss
[self dismissViewControllerAnimated:YES completion:nil];
Is there any way to achieve this in navigationController?
Don't link Storyboard
Present ViewController with this code
It Will Present from bottom to top
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"MYUnicornViewController"]; // Change the view controller name
[self.navigationController presentViewController:vc animated:YES completion:nil];
Dismiss ViewController with this code
It Will dismiss from top to bottom
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
You can present the view controller like as answered by #PinkeshGjr,
I am adding code to add navigation bar without the custom view suggested by #Pinkeshgjr.
Instead you can simply add your view controller in Navigation controller and present.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];//Change your storyboard name
UIViewController* myCopntroller = [storyBoard instantiateViewControllerWithIdentifier:#"myViewController"];//Your view controller
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:myCopntroller];//Added in navigation controller
[self presentViewController:nav animated:YES completion:nil];//Present you viewcontroller
Objective C:
Present from Bottom to Top
RegisterViewController *registerView = (RegisterViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"RegisterViewController"];
[self.navigationController presentViewController:registerView animated:YES completion:nil];
Dismiss from Top to Bottom
[self dismissViewControllerAnimated:YES completion:nil];
Swift:
Present from Bottom to Top
let registerView = self.storyboard?.instantiateViewController(withIdentifier: "RegisterViewController") as! RegisterViewController
self.navigationController?.present(registerView, animated: true, completion: nil)
Dismiss from Top to Bottom
self.navigationController?.dismiss(animated: true, completion: nil)
I'm presenting a SecondViewController modally on FirstViewController and the SecondViewController has a semi transparent background (White color with 70 percent opacity).
The problem I'm facing is when I present SecondViewController, the view of FirstViewController remains visible until the SecondViewController has finished presenting.
This makes the UI look laggy. The behaviour I'm expecting is as soon as the SecondViewController is presented, the view for FirstViewController should be invisible, or gradually faded out before the view of SecondViewController appears.
Any help will be greatly appreciated!
The code I use for presenting is :
SecondViewController *cntrlr = (SecondViewController *)[[UIStoryboard activationStoryboard] instantiateViewControllerWithIdentifier:#“UserVC”];
[cntrlr setModalPresentationStyle:UIModalPresentationPopover];
[self presentViewController:cntrlr animated:YES completion:nil];
After iOS 3.2 there is a method to do this without any “tricks” – see the documentation for the modalPresentationStyle property. You have a rootViewController which will present the viewController. So here's the code to success:
viewController.view.backgroundColor = [UIColor clearColor];
rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[rootViewController presentModalViewController:viewController animated:YES];
With this method the viewController's background will be transparent and the underlying rootViewController will be visible.
SecondViewController *cntrlr = (SecondViewController *)[[UIStoryboard activationStoryboard] instantiateViewControllerWithIdentifier:#“UserVC”];
[cntrlr setModalPresentationStyle:UIModalPresentationPopover];
self.view.alpha = 0.0f;
[self.navigationController.navigationBar setHidden:YES];
[self presentViewController:cntrlr animated:YES completion:nil];
// Need to set FirstViewController alpha 1.0f after dismisViewController
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.view.alpha = 1.0f;
[self.navigationController.navigationBar setHidden:NO];
}
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
There is iPad application with UINavigationBar and UITabBar.
I would like to show another UIViewController (clearColored with red UIView as a subview) with "blocking" UINavigationBar and UITabBar from the tap.
How can I do it?
EDITED
if I use [self presentViewController:aboutView animated:YES completion:nil]; :
it covers all with black background ((
[self.tabBarController.navigationController setNavigationBarHidden:TRUE];
[self.navigationController setNavigationBarHidden:TRUE];
self.tabBarController.hidesBottomBarWhenPushed = YES;
[self presentViewController:VC animated:YES completion:nil];
You can present a UIViewController which will obscure the underlying UITabBarController and UINavigationBarController. Try:
[self presentViewController:aViewController animated:YES completion:nil];
Keep in mind that you will be responsible for dismissing this presented view controller by calling dismissViewControllerAnimated: on the presenting view controller.
Try this
ViewController *detailview =[[ViewController alloc]initWithNibName:#"ViewController" bundle:nil]
[self.tabBarController presentViewController:detailview animated:YES completion:nil];