iOS PresentViewController与键盘

时间:2018-04-26 18:13:08

标签: ios swift animation keyboard presentviewcontroller

我真的在用键盘挣扎!我有一个viewController,我提出这样:

self.present(viewController, animated: true, completion: nil)

在这个viewController中,我有一个textFirstResponder这样的文本字段:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.textField.becomeFirstResponder()
}

问题在于,当视图出现时,键盘才弹出。它根本不光滑。我想在本机iOS应用程序中完全像消息:当您单击撰写消息(右上角)时。它呈现一个新的 viewController 键盘,所有动画

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

尝试在becomeFirstResponder()内放置viewDidLayoutSubviews()

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    textField.becomeFirstResponder()
}

答案 1 :(得分:0)

将其移动到viewDidAppear

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    self.textField.becomeFirstResponder()
}