Whenever I push to a new View Controller, a weird animation glitch where the title stays even after another view controller is loaded and does not animate to the back button. It only happens while pushing to a View Controller when large title is showing. I cannot understand why it's happening.
This is my Main View Controller.
'''
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var tblUserList: UITableView!
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var constTableViewHeight: NSLayoutConstraint!
let searchController = UISearchController(searchResultsController: nil)
let names = ["Rajesh Hamal", "Rishi Dhamala", "Salman Khan", "Shilpa Shetty", "Majnu Bhai", "Uday Shetty","Rajesh Hamal", "Rishi Dhamala", "Salman Khan", "Shilpa Shetty", "Majnu Bhai", "Uday Shetty"]
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.searchController = searchController
tblUserList.register(UINib(nibName: "UserListCell", bundle: nil), forCellReuseIdentifier: "UserListCell")
}
override func viewWillAppear(_ animated: Bool) {
navigationController?.navigationBar.prefersLargeTitles = true
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
self.constTableViewHeight?.constant = self.tblUserList.contentSize.height
}
@IBAction func btnAddUser(_ sender: UIButton) {
let vc = UIStoryboard(name: "AddUser", bundle: nil).instantiateViewController(withIdentifier: "AddUser") as! AddUser
navigationController?.pushViewController(vc, animated: true)
}
} '''
And this is the view controller that I am pushing to:
''' import UIKit import IBAnimatable
class AddUser: UIViewController, UIImagePickerControllerDelegate & UINavigationControllerDelegate {
@IBOutlet weak var imgProfilePicture: AnimatableImageView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
navigationController?.navigationBar.prefersLargeTitles = false
}
@IBAction func btnChooseProfilePicture(_ sender: UIButton) {
let alert = UIAlertController(title: "Choose Image", message: nil, preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: .default, handler: { _ in
self.openCamera()
}))
alert.addAction(UIAlertAction(title: "Gallery", style: .default, handler: { _ in
self.openGallery()
}))
alert.addAction(UIAlertAction.init(title: "Cancel", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
}
func openGallery()
{
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.photoLibrary){
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.allowsEditing = true
imagePicker.sourceType = UIImagePickerController.SourceType.photoLibrary
self.present(imagePicker, animated: true, completion: nil)
}
else
{
let alert = UIAlertController(title: "Warning", message: "You don't have permission to access gallery.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let pickedImage = info[.originalImage] as? UIImage {
self.imgProfilePicture.image = pickedImage
}
picker.dismiss(animated: true, completion: nil)
}
func openCamera()
{
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerController.SourceType.camera
imagePicker.allowsEditing = false
self.present(imagePicker, animated: true, completion: nil)
}
else
{
let alert = UIAlertController(title: "Warning", message: "You don't have camera", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
}
'''

ViewControllertry to implementviewWillDisappear. There you should be able to setnavigationController?.navigationBar.prefersLargeTitles = false.navigationController?.pushViewController(vc, animated: true)?