是否已在viewDidAppear上显示键盘?

时间:2014-04-20 01:25:19

标签: ios uitextview uipageviewcontroller uikeyboard

我有一个UIPageViewController初始化了三个控制器。当我向右滑动时,我正在呈现UIView,其UITextView成为第一个响应者。我想要实现的是当用户向右滑动时,键盘已经出现,当他们滑动以在其视图中隐藏键盘时。似乎键盘被添加到窗口? Facebook似乎在发布新帖子时实现了这一点,键盘似乎在视图出现之前加载了?

当我在UITextView上调用becomeFirstResponder时,我能够在不动画键盘的情况下显示键盘。但键盘出现的时间似乎有所延迟。

self.composeView.bodyTextView.inputAccessoryView = [UIView new];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(willShowKeyboard:)
                                             name:UIKeyboardWillShowNotification
                                           object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(didShowKeyboard:)
                                             name:UIKeyboardDidShowNotification
                                           object:nil];

1 个答案:

答案 0 :(得分:1)

似乎显示视图控制器并同时弹出键盘会造成一些延迟 所以我的建议是让键盘稍后出现。您可以将[textView becomeFirstResponder]放在viewDidAppear:中或者将UITextField子类化为覆盖didMoveToSuperview(在其上放置[self becomeFirstResponder])。

相关问题