我有一个视图应该是完全在键盘上,但我没有使用UITextView,所以我不能使用inputAccesoryView。
无论如何,在iOS 5之前我没有遇到任何问题,问题在于未插入/拆分键盘。现在,我必须使用UIKeyboardWillChangeFrameNotification来监听键盘框架的变化,所以我这样做
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyFrameChanged:)
name:UIKeyboardWillChangeFrameNotification
object:self.view.window];
因此,一旦移动键盘,就会调用以下内容
- (void) keyFrameChanged:(NSNotification *)notification
{
NSDictionary* userInfo = [notification userInfo];
CGRect keyboardEndFrame;
[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
// Animate view with keyboardEndFrame data
}
问题是,99%的时候,UIKeyboardFrameEndUserInfoKey返回null,所以我对键盘的位置没有任何线索。
谢谢!
PS:我设法将视图作为inputAccesoryView附加,通过覆盖我的UIResponder子类中的此属性(不再是readonly),但我仍然想知道如何跟踪键盘的帧。