在textView中输入时避免键盘的遮挡
2013-08-09 21:28
399 查看
很多时候我们都在为键盘遮挡了原本就不大的屏幕时而烦恼,特别是当用户处于编辑状态时,键盘下面的内容就看不见了,用户只能处于盲打状态了。现在有一种简单的解决办法,基本思路就是,添加通知。一直监听键盘事件,在键盘遮挡时,将编辑器上移键盘的高度,键盘消失时,编辑区回复原来位置,ok,来两段代码吧
各位亲
有时间可以去看看我的 “金骏家居淘宝店” http://jinjun1688.taobao.com/shop/view_shop.htm?tracelog=twddp 买时说明在我的博客看到有优惠哦
还有意外礼品赠送 真正的程序员淘宝店
[cpp]
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.textView=[[UITextView alloc]initWithFrame:self.view.frame];
self.textView.text=@"请输入文字";
[self.view addSubview:self.textView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated
{
//注册通知,监听键盘出现
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(handleKeyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
//注册通知,监听键盘消失事件
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(handleKeyboardDidHidden)
name:UIKeyboardDidHideNotification
object:nil];
[super viewWillAppear:YES];
}
//监听事件
- (void)handleKeyboardDidShow:(NSNotification*)paramNotification
{
//获取键盘高度
NSValue *keyboardRectAsObject=[[paramNotification userInfo]objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect;
[keyboardRectAsObject getValue:&keyboardRect];
self.textView.contentInset=UIEdgeInsetsMake(0, 0,keyboardRect.size.height, 0);
}
- (void)handleKeyboardDidHidden
{
self.textView.contentInset=UIEdgeInsetsZero;
}
- (void)viewDidDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
各位亲
有时间可以去看看我的 “金骏家居淘宝店” http://jinjun1688.taobao.com/shop/view_shop.htm?tracelog=twddp 买时说明在我的博客看到有优惠哦
还有意外礼品赠送 真正的程序员淘宝店
[cpp]
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.textView=[[UITextView alloc]initWithFrame:self.view.frame];
self.textView.text=@"请输入文字";
[self.view addSubview:self.textView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated
{
//注册通知,监听键盘出现
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(handleKeyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
//注册通知,监听键盘消失事件
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(handleKeyboardDidHidden)
name:UIKeyboardDidHideNotification
object:nil];
[super viewWillAppear:YES];
}
//监听事件
- (void)handleKeyboardDidShow:(NSNotification*)paramNotification
{
//获取键盘高度
NSValue *keyboardRectAsObject=[[paramNotification userInfo]objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect;
[keyboardRectAsObject getValue:&keyboardRect];
self.textView.contentInset=UIEdgeInsetsMake(0, 0,keyboardRect.size.height, 0);
}
- (void)handleKeyboardDidHidden
{
self.textView.contentInset=UIEdgeInsetsZero;
}
- (void)viewDidDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
相关文章推荐
- 在textView中输入时避免键盘的遮挡
- 在textView中输入时避免键盘的遮挡
- 当textField输入框被键盘遮挡时 让整个view上移
- textView键盘被遮挡问题
- iOS textView光标位置输入以及删除字符或者emoji表情(自定义键盘的删除方法)
- 键盘遮挡控件(textfield/textview.......)
- 用TPKeyboardAvoiding(Scroll,Collection,Table,text)View避免键盘遮盖住了textfield,textview
- iOS 处理键盘遮挡TextField、TextView问题
- iOS避免键盘遮挡输入方案
- Android 在TextView,EditText中添加表情,设置输入键盘消失
- TableView的Cell中有Textfield、TextView时放置键盘遮挡输入框
- TextView输入文本时Android软键盘出现时把布局向上顶
- AutoCompleteTextView(输入提示)和自定义键盘
- UI中消掉键盘+回车输入下一个+textview的一些基本操作
- IOS TextFiled与TextView 键盘的收起以及处理键盘遮挡
- iOS TextFiled、TextView 关于键盘的收起以及处理键盘遮挡
- iOS TextField 弹出键盘时实现view整体上移下移:防止弹出键盘遮挡输入框
- ios自定义TextView,实时监控输入字数的改变,计数以及超出时键盘自动隐藏
- IOS开发 textView输入文字时键盘切换为中文输入法后,第一个输入的字母变成英文
- [ios]TableView的Cell中有Textfield时放置键盘遮挡输入框