I have a simple tap bar example. And for my next view i have a ViewController with tableView and on bottom textInput. when i want hide tap bar i have a code:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject? {
if segue.identifier == "showMe" {
(segue.destinationViewController as! MyViewController)
destinationController.hidesBottomBarWhenPushed = true
}
}
and on my next view when i tap a row on tableView i see first rendering tap bar and then tap bar is hidden and on last input Edit goes down :( how hide this tap bar before show next screen ?
This isn't exactly the best solution, but its a workaround:
set destinationController.hidesBottomBarWhenPushed = false
set contraints properly in your view controller (as if there is no tab bar)
use the following code (as shown) in the view controller where you want to hide the tab bar:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tabBarController?.tabBar.frame = CGRectZero
self.tabBarController?.tabBar.userInteractionEnabled = false
}
This will make sure that the tab bar is hidden. Now the Autolayout constraints will make sure your view displays correctly with the tab bar height as zero.
Related
I have a View Controller which segues from a previous controller that has large titles. The navigation bar in the navigation controller has the Prefers Large Titles checkbox checked.
I have added a Table View to this new view controller. Until then, the title remains large. However as soon as I add prototype cells to the table view, the navigation bar becomes small.
In code I added this:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
navigationController?.navigationBar.prefersLargeTitles = true
}
The problem is, when the view controller comes into view, the title appears small for a second and then immediately shifts to large title.
How can I fix it so that it appear large as I segue and avoid that size shift once the title becomes visible?
it is a feature: when the user scroll, the large Title will disappear and show small title on top.
your problem happend because in the xib file:
your layout is small title and its change to largeTitle when it pushed.
but the view doesn't know that.
to fix this you just need to call: view.layoutIfNeeded() in the viewDidLoad() method.
override func viewDidLoad() {
super.viewDidLoad()
title = "Large title"
view.layoutIfNeeded()
}
Background:
My storyboard flow: [Nav VC] -> [VC1] -> [Home VC] -> [Settings VC] -> ...
I am currently using the Hero transition animation library to achieve a pull down effect (from top to bottom) when segueing from my Home VC to the Settings VC. In the storyboard have made sure to have hero enabled on my Nav, as well as the Home and Settings VC. As for the actual segue code this is what I have in the Home VC:
//in Home View Controller
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if(segue.identifier == "goToEditScreen") {
let editVC = segue.destination as! ProfileMenuViewController
//set the animation style
editVC.hero.modalAnimationType = .selectBy(presenting: .slide(direction: .down), dismissing: .slide(direction: .up))
editVC.documentID = self.documentID
}
}
The Issue:
The custom animation does not seem to be triggering, instead defaulting to the basic left to right segue. However, in the storyboard if deselect Navigation VC as the 'Initial View Controller', and instead change it to the 'VC1', then the Hero animation works (with the caveat that the Nav Bar is gone from the app).
What I Have Tried:
Like mentioned above I have tried switching the initial VC to not be the Nav VC and it seemed to work except I lose the nav bar. I also tried adding the same Hero code to the Settings VC in viewDidLoad()
hero.modalAnimationType = .selectBy(presenting: .slide(direction: .down), dismissing: .slide(direction: .up))
but to no avail, so I removed it.
If anyone has any insight into why this might be happening, please let me know!
In my app I'm using some pickerviews that appear when I click on a textfield, that works fine!
I wanted to do the same when I click on a Left Bar Button Item. I can't do it with the button because buttons doesn't have inputView property, needed for associate the pickerview to the button (in this case). So I want to have a hidden textfield that is programmatically clicked when I click on the button (when it's clicked it show the pickerview and change the button name, that's all done)
Is that possible?
The best I can do right know is something like this
txtFantasma.perform(
#selector(becomeFirstResponder),
with: nil,
afterDelay: 0.1
)
It works fine, but just work at the first time.
EDIT1:
I've tried to make it with buttons... The popover is showing, now I wanted to click in one button and dismiss the popover and pass data to the main viewcontroller.
class ViewPopup:UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func btTituloAsc(_ sender: UIButton) {
let next = self.storyboard?.instantiateViewController(withIdentifier: "mainview") as! ViewController
next.ordenacao = "TituloAsc"
self.present(next, animated: true,completion:nil)
}
}
This works, but the main controller is showed without the Navigation Bar! How can I do the same but show de Navigation Bar?
The simplistic way to do it, is just display the pickerView as a popover once the user taps the button and then change the buttons title accordingly.
Im currently designing an app that utilizes a tab bar controller.
On the messages tab (instant messages), I want the tab bar to disappear whenever a user is having/viewing his/her conversation with another person. To do so I used this:self.tabBarController?.tabBar.isHidden = true
It disables the tabBar, but now the issue is that whenever I hit the back button to return to previous views (embedded in a navigation controller), the tab bar is still hidden. On the other views, I've set tabBar.isHidden = false, but that doesn't seem to fix it and now I can't access any of the other tabs.
My question is: How can I hide the tabBar on one view but keep it visible when I return to previous views?
In TabBar firstViewController
override func viewWillAppear(animated: Bool) {
// Enable TabBar
self.tabBarController?.tabBar.hidden = false
}
In SecondViewController (Pushed from firstViewController)
override func viewDidLoad() {
super.viewDidLoad()
// Disable TabBar
self.tabBarController?.tabBar.hidden = true
}
I'm trying to hide navigation bar when I scroll my table view. It seems that when I scroll inside table view this one can't detect the scrolling event.. when I scroll outside table view navigation bar get hidden...how can I resolve ?
You need to set the navigation controller hideBarsOnSwipe to true
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.hidesBarsOnSwipe = true
}