问题描述
UITextView 插入到 UITabBarController 的标签中(在 iPhone 上).
There's UITextView inserted into tab in UITabBarController (on the iPhone).
- 用很多行填充
UITextView. - 显示键盘以编辑文本.
发生了什么?键盘用光标隐藏了 UITextView 的一半.结果无法编辑文本.
What's happen? The keyboard hide a half of UITextView with cursor. Can't edit the text as the result.
如何解决所有 Apple 移动设备(屏幕分辨率不同)的问题?非常感谢您的帮助!
How to resolve the issue for all Apple mobile devices (with different screen resolution)? Thanks a lot for help!
推荐答案
多年过去了,问题仍然存在.苹果绝对应该自己处理所有这些事情.但事实并非如此.这是基于 Apple 官方 文档加上错误修复.它支持 iOS 8、iOS 9、inputAccessoryView,并为新版本的 iOS 和新设备做好了准备.
Years gone, the question is still actual. Apple definitely should handle all these things itself. But it doesn't. Here's the new solution based on the official Apple's documentation plus bug fixes. It supports iOS 8, iOS 9, inputAccessoryView and is ready for new versions of iOS and new devices.
/* Apple's solution to resize keyboard but with accessory view support */
- (void)keyboardDidShow:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];
CGRect keyboardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
double keyboardHeight = [[UIScreen mainScreen] bounds].size.height - keyboardFrame.origin.y;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardHeight, 0.0);
editor.contentInset = contentInsets;
editor.scrollIndicatorInsets = contentInsets;
}
- (void)keyboardWillHide:(NSNotification*)aNotification {
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
editor.contentInset = contentInsets;
editor.scrollIndicatorInsets = contentInsets;
// button to hide the keyboard
buttonDone.enabled = false;
}
/* Fix issues with size classes and accessory view */
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
// fix incorrect size of the inputAccessoryView when size class changed
// willTransitionToTraitCollection and traitCollectionDidChange can't help us
if (editor && editor.inputAccessoryView && !editor.inputAccessoryView.hidden) {
[editor resignFirstResponder];
}
}
/* Hide accessory view if a hardware keyboard is present */
#define gThresholdForHardwareKeyboardToolbar 160.f // it's minimum height of the software keyboard on iPhone 4 in landscape mode
- (bool)isExternalKeyboard:(NSNotification*)aNotification {
NSDictionary* info = [aNotification userInfo];
CGRect keyboardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
double keyboardHeight = [[UIScreen mainScreen] bounds].size.height - keyboardFrame.origin.y;
return keyboardHeight < gThresholdForHardwareKeyboardToolbar;
}
- (void)keyboardWillShow:(NSNotification*)aNotification {
if ([self isExternalKeyboard:aNotification]) {
// hardware keyboard is present
if (editor && editor.inputAccessoryView) {
editor.inputAccessoryView.hidden = true;
}
} else {
// only on-screen keyboard
if (editor && editor.inputAccessoryView) {
editor.inputAccessoryView.hidden = false;
}
}
// button to hide the keyboard
buttonDone.enabled = true;
}
这篇关于出现键盘时如何在iOS上调整UITextView的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)