1

I put a UILabel in an inputAccessoryView as a kind of placeholder for text view. When my app is built and run, and the view controller is pushed on the navigation stack for the first time, everything works fine. However, for all subsequent pushes, the UILabel is invisible until the view controller is fully presented.

enter image description here Note the "Leave a comment" at the bottom

I also found that if I don't call setNavigationBarHidden, the problem goes away. Below is part of the code. ExpandableIAView is just a custom UIView with placeholder UILabel added using auto layout.

class DetailedPageController: UICollectionViewController {

    lazy var inputContainerView: ExpandableIAView = {
        let view = ExpandableIAView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
        view.delegate = self
        return view
    }()

    override var inputAccessoryView: UIView? {
        get {
            return inputContainerView
        }
    }

    override var canBecomeFirstResponder: Bool {
        return true
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.setNavigationBarHidden(true, animated: false)
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        navigationController?.setNavigationBarHidden(false, animated: true)
    }

}

ExpandableIAView

Copied directly from here (how can i increase the height of an inputAccessoryView). The placeholder UILabel is constrained to the top, left, and bottom anchors of the view.

Jack Guo
  • 3,959
  • 8
  • 39
  • 60

0 Answers0