我正在开发一个聊天应用程序,它在聊天屏幕的底部有一个工具栏(带有UITextView
和其他按钮),就像whatsapp一样,它根据键盘的可见性上下移动,直到iOS正常工作7。
我已经使用UIKeyboardDidChangeFrameNotification
基于我使用以下代码获取键盘框架
CGRect kKeyBoardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
并相应地设置工具栏的框架。
但它不适用于具有预测文本的iOS 8。 任何帮助表示感谢。
修改
当预测文本视图向上或向下移动时, UIKeyboardDidChangeFrameNotification
不会被激活。
追加快照
答案 0 :(得分:-1)
<强> UIKeyboardDidChangeFrameNotification 强>
在键盘框架发生变化后立即发布。
通知对象为零。 userInfo字典包含有关键盘的信息。使用键盘通知用户信息键中描述的键从userInfo字典中获取键盘的位置和大小。
在iPhone 6,iOS 10,9,8.4上测试(链接,构建,运行,请参阅下面的日志)。
NSNotification
字典显示CGRect
和UIKeyboardFrameBeginUserInfoKey
中UIKeyboardFrameEndUserInfoKey
值的反转。 UIKeyboard__Notification
,并且在更改预测附件视图时会触发所有4 func addObserver(forName: Notification.Name) {
NotificationCenter.default.addObserver(forName: forName,
object: nil,
queue: OperationQueue.main)
{ (note:Notification!) -> Void in
print("\(forName): \(note)")
}
}
addObserver(forName: .UIKeyboardWillShow)
addObserver(forName: .UIKeyboardDidShow)
addObserver(forName: .UIKeyboardWillChangeFrame)
addObserver(forName: .UIKeyboardDidChangeFrame)
。
Swift 3
conv2d = T.signal.conv.conv2d
x = T.dmatrix()
y = T.dmatrix()
veclen = x.shape[1]
conv1d_expr = conv2d(x, y, image_shape=(1, veclen), border_mode='full')
conv1d = theano.function([x, y], outputs=conv1d_expr)
开启预测
日志:
UIKeyboardWillChangeFrameNotification:
UIKeyboardWillShowNotification:
UIKeyboardDidChangeFrameNotification:
UIKeyboardDidShowNotification:
userInfo = { UIKeyboardBoundsUserInfoKey =“NSRect:{{0,0},{375,258}}”; UIKeyboardCenterBeginUserInfoKey =“NSPoint:{187.5,554.5}”; UIKeyboardCenterEndUserInfoKey =“NSPoint:{187.5,538}”; UIKeyboardFrameBeginUserInfoKey =“NSRect:{{0,442},{375,225}}”; UIKeyboardFrameEndUserInfoKey =“NSRect:{{0,409},{375,258}}”; }
关闭预测
日志:
UIKeyboardWillChangeFrameNotification:
UIKeyboardWillShowNotification:
UIKeyboardDidChangeFrameNotification:
UIKeyboardDidShowNotification:
userInfo = { UIKeyboardBoundsUserInfoKey =“NSRect:{{0,0},{375,225}}”; UIKeyboardCenterBeginUserInfoKey =“NSPoint:{187.5,538}”; UIKeyboardCenterEndUserInfoKey =“NSPoint:{187.5,554.5}”; UIKeyboardFrameBeginUserInfoKey =“NSRect:{{0,409},{375,258}}”; UIKeyboardFrameEndUserInfoKey =“NSRect:{{0,442},{375,225}}”; }
►在GitHub上找到此解决方案,并在Swift Recipes上找到其他详细信息。