根据键盘和预测文本视图iOS 8向上或向下移动我的工具栏

pan*_*kaj 6 iphone keyboard uiview ios8

我正在开发一个聊天应用程序,它UITextView在聊天屏幕的底部有一个工具栏(带有和其他按钮),就像whatsapp一样,它根据键盘的可见性上下移动,直到iOS 7 才能正常工作.

我已经UIKeyboardDidChangeFrameNotification使用了以下代码,我用它来获取键盘框架

  CGRect kKeyBoardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
Run Code Online (Sandbox Code Playgroud)

并相应地设置工具栏的框架.

但它不适用于具有预测文本的iOS 8.任何帮助赞赏.

编辑:

UIKeyboardDidChangeFrameNotification 当预测文本视图向上或向下移动时,不会被激起.

附加快照

图像与预测文本 在此输入图像描述

Swi*_*ect -1

iOS 10、9 一直降到 5

\n\n
\n

UIKeyboardDidChangeFrameNotification

\n\n

在键盘\xe2\x80\x99s 框架发生更改后立即发布。

\n\n

通知对象为零。userInfo 字典包含有关键盘的信息。使用键盘通知用户信息键中描述的键从 userInfo 字典中获取键盘的位置和大小。

\n
\n\n

在 iPhone 6、iOS 10、9、8.4 上进行测试(链接、构建、运行,请参阅下面的日志)。

\n\n

字典显示&中值NSNotification的反转,并且当预测附件视图更改时,所有 4 个值都会被触发。CGRectUIKeyboardFrameBeginUserInfoKeyUIKeyboardFrameEndUserInfoKeyUIKeyboard__Notification

\n\n

雨燕3

\n\n
func addObserver(forName: Notification.Name) {\n    NotificationCenter.default.addObserver(forName: forName,\n                                           object: nil,\n                                           queue: OperationQueue.main)\n    { (note:Notification!) -> Void in\n        print("\\(forName): \\(note)")\n    }\n}\n\naddObserver(forName: .UIKeyboardWillShow)\naddObserver(forName: .UIKeyboardDidShow)\naddObserver(forName: .UIKeyboardWillChangeFrame)\naddObserver(forName: .UIKeyboardDidChangeFrame)\n
Run Code Online (Sandbox Code Playgroud)\n\n

打开预测

\n\n

在此输入图像描述

\n\n

日志:

\n\n
\n

UIKeyboardWillChangeFrameNotification:
\n UIKeyboardWillShowNotification:
\n UIKeyboardDidChangeFrameNotification:
\n UIKeyboardDidShowNotification:
\n userInfo = {\n UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {375, 258}}";\n UIKeyboardCenterBeginUserInfoKey = "NSPoint: {187.5 , 554.5}";\n UIKeyboardCenterEndUserInfoKey = "NSPoint: {187.5, 538}";\n UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 442}, {375, 225}}";\n UIKeyboardFrameEndUserInfoKey = "NSRect: {{ 0, 409}, {375, 258}}";\n }

\n
\n\n

关闭预测

\n\n

在此输入图像描述

\n\n

日志:

\n\n
\n

UIKeyboardWillChangeFrameNotification:
\n UIKeyboardWillShowNotification:
\n UIKeyboardDidChangeFrameNotification:
\n UIKeyboardDidShowNotification:
\n userInfo = {\n UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {375, 225}}";\n UIKeyboardCenterBeginUserInfoKey = "NSPoint: {187.5 , 538}";\n UIKeyboardCenterEndUserInfoKey = "NSPoint: {187.5, 554.5}";\n UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 409}, {375, 258}}";\n UIKeyboardFrameEndUserInfoKey = "NSRect: {{ 0, 442}, {375, 225}}";\n }

\n
\n\n
\n\n

\xe2\x96\xba 在GitHub上找到此解决方案,并在Swift Recipes上找到其他详细信息。

\n