无法移动键盘视图iOS9 swift [英] Can't move keyboard view iOS9 swift
问题描述
我需要实现一个不屑一顾的键盘(向下滑动以解除),就像在iOS上的股票消息应用程序中那样。
I need to implement a dismissive keyboard (swiping down to dismiss) like the one in the stock messages app on iOS.
我有这个代码来获取键盘查看:
I have this code to get the keyboard view:
func keyboardWillShowWithNotification(notification:NSNotification) {
let keyboardView = accessoryView.superview
}
我连接了tableView的UIPanGestureRecognizer,以检测我何时需要开始移动键盘。
And I connected the UIPanGestureRecognizer of the tableView to detect when I need to start moving the keyboard down.
func handleTableViewPan(gr:UIPanGestureRecognizer) {
let location = panGestureRecognizer.locationInView(self.view)
let offset = ... //calculated correctly
keyboardView.frame.origin.y = originalKeyboardFrame.origin.y + offset
}
这个方法适用于iOS 8,但是对于iOS 9,似乎键盘保持不变,所以我无法移动它。
也许有人遇到了同样的问题,可以帮助我。
谢谢。
The method worked fine with iOS 8 but with iOS 9 it seems like the keyboard is hold in place a little different so I can't move it. Maybe someone encountered the same problem and can help me. Thank you.
推荐答案
在iOS 9中有一个名为UIRemoteKeyboardWindow的键盘新窗口,所以当你使用accessoryView.superview你会得到一个错误的视图。
In iOS 9 there is a new window for keyboard named UIRemoteKeyboardWindow, so when you are using accessoryView.superview you will get a wrong view.
要获得正确的视图,请尝试直接从窗口层次结构中找到它:
(objective-c code)
To get correct view try to find it from window hierarchy directly: (objective-c code)
-(UIView*)getKeyboardInputView {
if([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {
for(UIWindow* window in [[UIApplication sharedApplication] windows])
if([window isKindOfClass:NSClassFromString(@"UIRemoteKeyboardWindow")])
for(UIView* subView in window.subviews)
if([subView isKindOfClass:NSClassFromString(@"UIInputSetHostView")])
for(UIView* subsubView in subView.subviews)
if([subsubView isKindOfClass:NSClassFromString(@"UIInputSetHostView")])
return subsubView;
} else {
return accessoryView.superview;
}
return nil;
}
P.S。取自DAKeyboardControl https://github.com/danielamitay/DAKeyboardControl/pull/98
P.S. Taken from DAKeyboardControl https://github.com/danielamitay/DAKeyboardControl/pull/98
这篇关于无法移动键盘视图iOS9 swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!