iOS - 获取系统键盘所在View
2017-01-11 15:55
1131 查看
做自定义键盘可能需要用到这个,也有用更高级别的Window盖住键盘,这个在键盘view上用自定义键盘盖住原键盘,但是记得不需要的时候就把自定义键盘移除,否则在哪都是自定义键盘
代码是从Stack Overflow找到的,好用
- (UIView *)keyboardView { UIWindow* tempWindow; //Because we cant get access to the UIKeyboard throught the SDK we will just use UIView. //UIKeyboard is a subclass of UIView anyways UIView* keyboard; NSLog(@"windows %ld", [[[UIApplication sharedApplication]windows]count]); //Check each window in our application for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; c ++) { //Get a reference of the current window tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c]; //Get a reference of the current view for(int i = 0; i < [tempWindow.subviews count]; i++) { keyboard = [tempWindow.subviews objectAtIndex:i]; NSLog(@"view: %@, on index: %d, class: %@", [keyboard description], i, [[tempWindow.subviews objectAtIndex:i] class]); if([[keyboard description] hasPrefix:@"(lessThen)UIKeyboard"] == YES) { //If we get to this point, then our UIView "keyboard" is referencing our keyboard. return keyboard; } } for(UIView* potentialKeyboard in tempWindow.subviews) // if the real keyboard-view is found, remember it. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { if([[potentialKeyboard description] hasPrefix:@"<UILayoutContainerView"] == YES) keyboard = potentialKeyboard; } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) { if([[potentialKeyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) keyboard = potentialKeyboard; } else { if([[potentialKeyboard description] hasPrefix:@"<UIKeyboard"] == YES) keyboard = potentialKeyboard; } } return keyboard; }
相关文章推荐
- 获取系统键盘所在的View
- IOS开发之自定义系统弹出键盘上方的view(转载)
- 键盘弹起与隐藏时高度的获取及动画 适配所有iOS系统
- iOS 获取系统键盘UIKeyboard方法
- iOS开发之获取view所在的控制器
- iOS获取系统键盘的高度
- 【iOS开发】获取当前view(视图)所在的Controller(控制器)
- iOS用WKWebView与JS交互获取系统图片及WKWebView的Alert,Confirm,TextInput的监听代理方法使用,屏蔽WebView的可选菜单
- iOS-获取当前View所在的控制器
- iOS-获取当前View所在的控制器
- iOS如何获取系统键盘的高度
- iOS-获取当前View所在的控制器
- IOS开发之自定义系统弹出键盘上方的view
- iOS下Html页面中input获取焦点弹出键盘时挡住input解决方案—scrollIntoView()
- iOS成长之路-获取系统键盘的高度
- IOS开发之自定义系统弹出键盘上方的view
- iOS开发之获取系统键盘的详细信息
- 如何获取视图view所在的控制器iOS
- iOS用WKWebView与JS交互获取系统图片及WKWebView的Alert,Confirm,TextInput的监听代理方法使用,屏蔽WebView的可选菜单
- 获取iOS系统emoji动画,并自定义emoji键盘