Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my inputAccessoryView disappear when navigating backwards?

I implemented an own inputAccessoryView within a VC that gets pushed by a UINavigationController.

This is how the VC looks like: Notice the inputAccessoryView at the bottom (the white bar with the button and a text field)

1]

When I swipe from the left to the right of the screen (in order to dismiss the current VC and go back), the inputAccessoryView moves down and disappears. In addition, if I stop the swipe gesture anywhere and let the current VC jump back (so that it won't be dismissed), the inputAccessoryView also moves down and disappears.

I attached another photo while moving: 2]

An another one after the VC jumped back:

3]

As you can see, the inputAccessoryView has disappeared.

My piece of code:

private final lazy var inputContainerView: UIView = {
    let containerView = UIView()
    containerView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: 50)
    [...]
    return containerView
}()
[...]


override var inputAccessoryView: UIView? {
    return inputContainerView
}

override var canBecomeFirstResponder: Bool {
    return true
}
like image 654
j3141592653589793238 Avatar asked Mar 06 '18 12:03

j3141592653589793238


1 Answers

You may want to try calling

self.becomeFirstResponder() in viewWillAppearor viewDidAppear both of them will be trigged when that happens.

like image 137
tpeodndyy Avatar answered Nov 10 '22 14:11

tpeodndyy