I tried same code mention in gist : https://gist.github.com/barbietunnie/e5547f35180436ac102cac52a15f8ca3
func showModal() {
let modalViewController = ModalViewController()
modalViewController.modalPresentationStyle = .OverCurrentContext
presentViewController(modalViewController, animated: true, completion: nil)
}
class ModalViewController: UIViewController {
override func viewDidLoad() {
view.backgroundColor = UIColor.clearColor()
view.opaque = false
}
}
Its working fine but in case of tab bar the content is getting beyond tab bar, How can we make content visible upper/front of tab bar?
It worked via vc.modalPresentationStyle = .overFullScreen
I hope it will work for you,
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let controller = mainStoryboard.instantiateViewController(withIdentifier: "ModalViewController") as! ModalViewController
controller.modalPresentationStyle = .overCurrentContext
Thank You.
Related
If I click on the push notification, it takes me to the details page but when I click on the programatically created back button, it takes me back to HomeVC but with the top nav bar gone. Here is my app delegate function where I present the details VC :
private func gotoDetailsVC(value : String)
{
guard let window = UIApplication.shared.connectedScenes.filter({$0.activationState == .foregroundActive
|| $0.activationState == .background || $0.activationState == .foregroundInactive}).compactMap({$0 as? UIWindowScene}).first?.windows.filter({$0.isKeyWindow}).first
else { return }
let storyboard = UIStoryboard(name: "Home", bundle: nil)
let detailsVC = storyboard.instantiateViewController(identifier: "viewDeviceDataController") as viewDeviceDataController
detailsVC.deviceID = value
detailsVC.didComeFromPN = true
let navController = UINavigationController(rootViewController: detailsVC)
navController.modalPresentationStyle = .popover
// you can assign your vc directly or push it in navigation stack as follows:
window.rootViewController = navController
window.makeKeyAndVisible()
}
And here is my back button on the DetailsVC :
#objc func backAction() {
let storyboard = UIStoryboard.init(name: "Home", bundle: nil)
let homeVC = storyboard.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
homeVC.modalPresentationStyle = .automatic
present(homeVC, animated: true, completion: nil)
}
How can I resolve this issue? Please help.
Resolved by navigating to root Navigation Controller.
#objc func backAction() {
let storyboard = UIStoryboard.init(name: "Home", bundle: nil)
let homeVC = storyboard.instantiateViewController(withIdentifier: "navControllerHome") as! UINavigationController
homeVC.modalPresentationStyle = .fullScreen
present(homeVC, animated: true, completion: nil)
}
Usually back action would just return to a previous state, but here it seems you are recreating the view.
I would not make private func gotoDetailsVC(value : String) replace rootViewController and instead make it be presented by current navigationController then on your back action you would not create a new home but dismiss your detail screen.
I am trying to switch between a view controller (that is coded programmatically) to a ViewController with the UI Elements on the storyboard.
I am trying to switch between a HomeController to a TabBarController using a button but by pressing the button it switches to a dark screen. I would be glad if some of you could help me out.
Here is my code:
var welcomeLabel: UIButton = {
let label = UIButton()
label.tintColor = .white
label.translatesAutoresizingMaskIntoConstraints = false
label.alpha = 0
label.addTarget(self, action: #selector(handleLogin), for: .touchUpInside)
return label
}()
...............
#objc func handleLogin() {
navigationController?.show(TabBarController(), sender: Any?.self)
}
use this code if you're pushing view from NavigationController
navigationController?.pushViewController("YourViewController", animated: true)
You can do it in following way
let storyboard = UIStoryboard(name: "Your_storyboard", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "Your_View_controller") as! Your_View_controller
Now to present
self.present(viewController, animated: true, completion: nil)
Or through navigation controller
navigationController?.pushViewController(viewController, animated: true)
You can try this -
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil) // Give the name .e.g if you have the different story board name
let YourNextViewController = storyBoard.instantiateViewController(withIdentifier: "your story board identifier") as! StoryBoardName/ClassName
self.navigationController?.pushViewController(YourNextViewController, animated: true)
//Or if you want to present viewController
self.present(YourNextViewController, animated:true, completion:nil)
I have 2 ViewControllers that are presenting a new ViewController.
The first is in a navigation controller so it works as expected with a segue push.
The second however is from a ViewController without a navigation bar. I'm programmatically presenting this view. However when the destination is presented there are 2 issues...
1) There is no navigation bar.
2) The view shown starts below the first TableViewCell.
func goToLocation() {
let locationTableVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "locationProfile") as! LocationTableViewController
locationTableVC.documentId = selectedDocumentId!
self.present(locationTableVC, animated: true, completion: nil)
}
LocationTableViewController.swift
// MARK: - View Will Appear
override public func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
UIApplication.shared.statusBarStyle = .lightContent
// Make Nav Bar Translucent and Set title font/color
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = .clear
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20, weight: .semibold)]
self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "back-arrow-white")
}
Segue shows starting below the first TableViewCell and without a navigation bar.
The first segue which I'm trying to recreate like the second looks like this...
Push your UIViewController with a UINavigationController, like this:
func goToLocation() {
let locationTableVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "locationProfile") as! LocationTableViewController
locationTableVC.documentId = selectedDocumentId!
let navigationController = UINavigationController(rootViewController: locationTableVC)
self.present(navigationController, animated: true, completion: nil)
}
I have a question regarding blureffects on a view controller. I program all of my segues manually for several reasons. But when I go to a viewcontroller that has a blureffect background, I only see a dark gray background. How can I solve this that the view controller blur effect lays on top of another viewcontroller where the content of the previous viewcontroller can be seen through?
The blureffects are now applied by storyboard with transparant background views.
My code for seque is:
Action:
#IBAction func ToUserSections(_ sender: Any) {
let controller =
Navigation.getDestinationViewControllerWith("User",
controllerName: "UserSectionsVC")
present(controller, animated: false, completion: nil)
}
Class:
class Navigation{
static func getDestinationViewControllerWith(_
storyboardName:String, controllerName:String)-> UIViewController{
let storyboard = UIStoryboard(name: storyboardName, bundle: nil)
let controller =
storyboard.instantiateViewController(withIdentifier:
controllerName) as UIViewController
return controller
}
}
Hope you can help me with this because it will maximize aesthetics for the app :D
try this.
let viewController : CustomViewControlller = UIStoryboard.getMainStoryboard().instantiateViewController(withIdentifier: "Identifier") as! CustomViewControlller
viewController.modalPresentationStyle = .overCurrentContext
viewController.modalTransitionStyle = .crossDissolve
self.present(viewController, animated: true, completion: { _ in })
Alright for others to know, what worked for me was the following:
At IBAction: adding the following line before presenting
controller.modalPresentationStyle = UIModalPresentationStyle.overFullScreen
Like this:
#IBAction func ToUserSections(_ sender: Any) {
let controller = Navigation.getDestinationViewControllerWith("User", controllerName: "UserSectionsVC")
controller.modalPresentationStyle = UIModalPresentationStyle.overFullScreen
present(controller, animated: false, completion: nil)
}
I am trying to set the background and trasparecy for UINavigation bar in code, in the ViewWillAppear func. however it doesn't seem to be working.
self.navigationController!.navigationBar.translucent = false
self.navigationController!.navigationBar.backgroundColor = UIColor.blackColor()
the view controller is load via the storyboard id
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier(storyboardId)
vc.title = storyboardId
let navigationController = UINavigationController(rootViewController: vc)
self.presentViewController(navigationController, animated: false, completion: nil)
i have tried setting it there too, doesn't seem to be working.
additionally i tried with UINavigationBar.appearance() to set the properties, this too doesn't work.
You can try with this:
self.navigationController?.barTintColor = UIColor.blackColor()