I have UIViewController
(first) which has tab bar at the bottom. I have next code in this controller:
let tabBarHeight = self.tabBarController?.tabBar.frame.size.height
It's working fine, but when I'm going from this first to next one (second) controller and then pressing Back
button and returning to first, self.tabBarController
is nil. Why does it happen? I have only one version, that stack of controllers is overcrowded.
How can I fix this? I need this height to calculate some value for constraint change in keyboardWillShow
function.
UPDATE:
How do I call it:
// MARK: - Scroll view on keyboard show/hide
extension CommentariesController: UITextFieldDelegate {
func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
let keyboardHeight = keyboardSize.height
let tabBarHeight = self.tabBarController?.tabBar.frame.size.height
UIView.animate(withDuration: 1.0, animations: {
self.newCommentViewBotConstraint.constant = -keyboardHeight + tabBarHeight!
self.view.layoutIfNeeded()
})
}
}
// other code
}
Update 2:
I can see tab bar
. But it is nil
.
Structure (with Show
segues): tabbar -> navbar -> viewcontroller -> viewcontroller -> viewcontroller (first) -> viewcontroller (second)
.
Thanks