I'm trying to recreate the effect where the view controller underneath the one I'm presenting onto the user's iPhone is positioned behind the presented view controller so you can see the top of the previous VC.
#objc func showSteps() {
let vc = UIStoryboard(name: Storyboards.Main.rawValue, bundle: nil).instantiateViewController(withIdentifier: HowToSteps.four.stepAsString())
vc.modalPresentationStyle = .pageSheet // I've also tried the other enum options here to no effect
let nc = UINavigationController(rootViewController: vc)
present(nc, animated: true)
}
However the presented view controller just comes up as full screen without the ability to see the view controller underneath behind it.
Any help here would be appreciated. Thanks!
Edit:
The effect I'm going for:
Related
I have two view controllers, first view controller and the second view controller, when the user segue from the first view controller to the second view controller, the first view controller still visible and sits behind the second view controller. The user can swipe the first view controller and see the entire first view controller and then they got stuck there. I noticed that this only happens after the launch of iOS 13.
performSegue(withIdentifier: "showSecond", sender: self)
Follow these two steps:
Click on the segue you created on the Storyboard
Go to Attributes Inspector
Set the Presentation to "Full Screen"
#Maysam is 100% right! But you can also do it programmatically through this:
// Go to next View Controller
#IBAction func nextTextVC(_ sender: UIButton) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let nextInfo = storyboard.instantiateViewController(identifier: "socialOptionsIntroViewController")
self.navigationController?.pushViewController(nextInfo, animated: true)
}
There is a more detail thread could answer this question.
The follow solution from Pratik Sodha
let controller = UIViewController()
let navigationController = UINavigationController(rootViewController: controller)
navigationController.modalPresentationStyle = .overCurrentContext
self.navigationController?.present(navigationController, animated: true, completion: nil)
I've separated my views into multiple storyboards to make managing the project as a team much easier. The only problem is that I want to have the navigation bar across all of my different view controllers. I embedded the first view controller in a navigation controller which added the navigation bar. In my second storyboard, I wanted to constrain a view to the navigation bar, however, since this view controller isn't embedded in a navigation controller, there isn't anything to constrain the view to. I put a navigation bar without a navigation controller to constrain to, however, when I perform the segue from the first storyboard, this results in two navigation bars. How do I make this so that I can constrain the view to the navigation bar without having two of them? Thanks in advance!
You can go from on view controller to another by three way:-
First using segue as you are already doing
second You can Present your view controller by
let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "someViewController")
self.present(controller, animated: true, completion: nil)
Third You can Navigate View controller by
let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "someViewController")
self.navigationController?.pushViewController(controller, animated: true)
I'm not sure your problem. I guess that you want to use ONE navigation bar to constrain many UIViewController in different Storyboard. Here is my answer.
Step 1: Set up Storyboard ID in each UIViewController
Step 2: push new UIViewController
func switchNextView() {
let storyboardName:String = "xxxxxx"
let storyboardId:String = "xxxxx"
let storyboard = UIStoryboard(name: storyboardName, bundle: nil)
let vc: UIViewController =
storyboard.instantiateViewController(withIdentifier: storyboardId) as!
UIViewController
self.navigationController?.pushViewController(vc, animated: true)
}
I have an app that I need to display a pin code screen every time the app is opened. I'm successfully displaying the modal view, but it doesn't cover the navigation bar at the top, and it doesn't cover the tab bar at the bottom. I believe it's because of how I'm presenting it, but I'm not seeing a way to change it.
This is how I'm presenting the controller
let newVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LoginView")
let view = window?.rootViewController as! UITabBarController
view.selectedViewController?.show(newVC, sender: nil)
This is the storyboard to give you an idea of the app.
The problem is your use of UIViewController's api, show. The function is overridden by UINavigationController in this case and push will be used to present the view controller. If your plan is to modally present a view controller, rather use present
selectedViewController?.present(newVC, animated: true, completion: nil)
I have created a TabBarController with 4 UIViewControllers. However, when I want to show one of the ViewControllers in the TabBarController with:
func gotoMainAppVC()
{
let mainVC:SearchVC = SearchVC()
self.present(mainVC, animated: true, completion: nil)
}
I only get a plain black screen. What am I doing wrong?
This is not how any of this works.
I am not sure what self is in your context but I expect it is either a tab bar controller or one of the view controllers on the tab bar.
By calling present it means you want to present a view controller on a current one which by default brings a new fullscreen view controller from bottom upwards.
Since you have created a new instance of view controller by calling SearchVC() this is not the view controller that you see in your storyboard. You may create any instances of any of your view controllers but in your case if you designed SearchVC in a storyboard you want to actually use that version of it. To do so you need to set storyboard id inside your storyboard. After you have done that you should initialise it as using:
UIStoryboard(name: <#T##String#>, bundle: nil).instantiateViewController(withIdentifier: <#T##String#>)
as in
let mainVC:SearchVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "TheIDIHaveSet") as! SearchVC
But again this will not give you the view controller that is inside your tab bar but create a new instance. And it will not instert it as one of the tabs but present a new full screen view controller.
This is my storyboard:
Short Description:
My App starts with the LaunchController
a modal segue shows the Reveal View Controller
this bring the Menu Controller and my Main Navigation Controller (ID
"NavController"; green Navbar) together. this will create a slide
menu. (Basic Code:
appcoda.com/ios-programming-sidebar-navigation-menu/)
my Main Navigation Controller shows a TableViewController.
this one have a menu button (3 Lines) which make the slide menu
visible
the plus icon willo push the last view Controller (ID: "VC1").
My Problem:
I would like to set quick actions for my app.
This code help works for that:
#available(iOS 9.0, *)
func handleShortcut( shortcutItem:UIApplicationShortcutItem ) -> Bool {
var succeeded = false
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewControllerWithIdentifier("NavController")
self.window?.rootViewController = initialViewController
let navVC = self.window?.rootViewController as! UINavigationController
switch shortcutItem.type {
default:
navVC.pushViewController(storyboard.instantiateViewControllerWithIdentifier("VC1"), animated: false)
succeeded = true
break
}
return succeeded
}
This Code set the NavController as initial Controller und push the to VC1.
This works fine.
With the X icon in VC 1, i use the unwind function back to TableView.
The Problem: if i use the undwind function and fall back to tableview i can't open the slide menu. A Touch on the menu icon give no reaction.
The Problem can be, that i start the app with the quick action behind the Reveal View Controller.
How can I solve this problem?
Did you try to make the reveal view controller the entry point of your app and deleting the launch controller, because if you just want to go back to the main view you could just do this :
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateInitialViewController() as UIViewController!
self.presentViewController(controller, animated: false, completion: nil)
If you cannot could you explain the purpose of the launch controller?