简体   繁体   中英

Don't close keyboard when presenting another UIViewController modally

When keyboard is open, I don't want it to close when I click a button that presents another ViewController modally. The ViewController that is being presented should cover the keyboard instead.

In iOS, the keyboard is a subview of an independent window, so it is always trying to be displayed in the front.

so the one you are expecting is not possible with presenting view controllers modally. system wants to keep the keyboard infront of all vcs, (for eg, if the keyboard kept alive in the old vc, then you cant invoke the keyboard in your new presented vc. bcoz keyboard obj is still alive) so by default it resigns the first responder when a new vc injected on the stack. but in pushing vc you can keep the keyboard alive by doing customization. apple setup tour does that way.

HINT you can put the becomeFirstResponder in the viewDidLoad of the view that is gonna presented. that may give feel like the keyboard is alive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM