I have set large title in viewWillAppear()
self.navigationItem.largeTitleDisplayMode = .always
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationItem.title = "Reports"
But still when I redirect to next VC and come back I can see navigation Title in small size for a while and then I see large title, anybody know why and how to fix it?
If you want the next VC to have largeTitleDisplayMode false, you could try to set it in viewWillDisappear() of the current VC, like this:
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.navigationBar.prefersLargeTitles = false
}
You should set this in the viewDidLoad of your view controller, not the viewWillAppear. It's the first part in the view lifecycle and where this work should be done
Related
In my use case, I want to hide the bottom tabbar when navigating away from UITabbarController.
I was using
let vc = storyboard?.instantiateViewController(withIdentifier: tableData[indexPath.row]["vcIdentifier"]!)
self.hidesBottomBarWhenPushed = true
self.show(vc!, sender: self)
It sorta works, because the pushed view controller doesn't have tabbar at bottom. However, as soon as I click on navigate, the bottom tabbar of the "sender" view controller vanishes and leaves black area.
Please let me know if you need to have more information about anything. Thanks a lot in advance!
If the pushed view controller doesn't have a tab bar at the bottom, you can add this lifecycle of view controller codes.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tabBarController?.tabBar.isHidden = true
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
tabBarController?.tabBar.isHidden = false
}
you can use segue if you want to hide tabbar while going to the next screen. it will automatically hide it.
Hi I've been trying to change my back button in my application's navigation bar. The problem is that I see the change when I load the view twice.
I've searched for the answer several times but I don't see what I really want. In fact, I'm new at this language so it's difficult.
What I tried is putting the following lines in the viewWillAppear method and others*:
nav?.navigationBar.backItem?.title = "Messages"
The result is that when I enter the view I see the back button's title as Back. Then if I press on that button and enter the view again the title changes as I want. On the other hand, what I want is to change the title when I load the view first.
*-> I've tried the same line in viewDidLoad too see if that does anything and in viewWillDisappear of the previous view, but nothing happens.
You are using method a change back button in your current ViewController it is wrong, because your navigationBar configured in past controller. If you use Storyboard, please will try this method in your parent controller:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let backItem = UIBarButtonItem()
backItem.title = "Messages"
navigationItem.backBarButtonItem = backItem
}
If you init newController in your parentController, you must to modify your a backButton in parentController, example:
// It's action for any button witch present your newController
#objc private func presentDetailViewContorller() {
let weatherDetailController = WeatherDetailController()
let navController = NavigationController(rootViewController: weatherDetailController)
let backItem = UIBarButtonItem()
backItem.title = "Messages"
navController.backBarButtonItem = backItem
self.present(navController, animated: true, completion: nil)
}
Good luck!
So on my first vc I have set the nav bar to a large title. Then I have a button which goes to a vc with a nav bar with a small title.
When I go back from my second vc to the first, it displays the small title for a bit then jumps down to the large title.
Here is my code in the first vc bc its a tab view controller:
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.prefersLargeTitles = true
}
Here is the code for the second vc in the viewDidLoad():
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.font: UIFont(name: "Avenir-Black", size: 20)!]
self.navigationController?.navigationBar.prefersLargeTitles = false
This is what I mean about the jumpy transition
Thanks
On your second ViewController Try changing the NavBarPreference inside viewWillDisappear function.
Example:
func viewWillDisappear(_ animated: Bool){
self.navigationController?.navigationBar.prefersLargeTitles = true
}
So before going back to the first vc you change the NavBar preference first
Alternative Solution: Using Storyboard
You can click on the desired VC then click on its navBarItem then go to your right to properties and on Large Title Select Never, Always or Automatic from the dropdown list.
Example
Short answer is to not rely on largeTitleDisplayMode = .automatic (the default value) and prefersLargeTitles = true/false but instead to be explicitly setting .always or .never with prefersLargeTitles = true (yes even when using never).
You need to always have prefersLargeTitles to be true because of this from Apple doc:
If the prefersLargeTitles property of the navigation bar is false, this property has no effect and the navigation item’s title is always displayed as a small title.
This is an issue you have on iOS11/12 but on iOS13 it will be surfaced a bit differently.
This is a Apple simple guide about Table Search with UISearchController, and I have downloaded the demo project and it is working well.
https://developer.apple.com/library/content/samplecode/TableSearch_UISearchController/Introduction/Intro.html
I want to have transparent navigation bar on product detail view (DetailViewController.swift). After changing some behaviors I have transition issue when going back from product detail to device list with swipe gesture(Video link below).
https://www.dropbox.com/s/denqomhhxasxv58/issue.mov?dl=0
For transparent navigation bar I have added this lines on DetailViewController
viewWillAppear method
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// ...
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
}
In MainTableViewController.swift I have added this code to make navigationBar default style.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
navigationController?.navigationBar.shadowImage = UIImage()
}
Also I made changes on MainTableViewController viewDidLoad method and sets this properties to true.
navigationItem.hidesSearchBarWhenScrolling = true
searchController.dimsBackgroundDuringPresentation = true
So my problem is to fix that issue. Anyone can help me?
Update:
Swipe transition from product detail to device list
Search controller active state when product detail not opened
Search controller active state after product detail opened
I have read multiple places with suggestions on how to accomplish this. I went with adding a UI view in the background and setting it to disable and then after showing the popover, setting the view to enable.
As you can see it looks to work nicely:
But I do have two problems. The first one is once the popover is presented, you can tap anywhere on the background to dismiss the popover. Is there anywhere to block this from happening? I assumed my background UIView would block any inputs.
Also, after the popover is dismissed, the screen is still dim. I tried the following but neither of them load after dismissing the popover so the View never gets set back to disable:
override func viewDidAppear(_ animated: Bool) {
dimView.isHidden = true
}
override func viewWillAppear(_ animated: Bool) {
dimView.isHidden = true
}
EDIT:
This is the code that I use to present the popover:
let popover = storyboard?.instantiateViewController(withIdentifier: "PopoverVC")
popover?.modalPresentationStyle = .popover
popover?.popoverPresentationController?.delegate = self as? UIPopoverPresentationControllerDelegate
popover?.popoverPresentationController?.sourceView = self.view
popover?.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
popover?.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
dimView.isHidden = false
self.present(popover!, animated: false)
I realize that, dimView is not in PopoverVC, add it into PopoverVC and handle dismiss when tap on it.After the popover is dismissed viewDidAppear and viewWillAppear will not be called. So your screen is still blurry.If you add dimView into Popover, hope you can solve these issuses
I think you could solve your two problems with the UIPopoverPresentationControllerDelegate and a protocol/ delegate to tell the presenting viewcontroller when your are dismissing and hide your dimView.
The first issue can be implemented like this:
extension YourViewController: UIPopoverPresentationControllerDelegate {
func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
return false
}
For the second issue you can pass a function through delegation. Hopefully this link will help with that.
https://matteomanferdini.com/how-ios-view-controllers-communicate-with-each-other/
Cheers