在textView中输入时避免键盘的遮挡
来源:未知 责任编辑:责任编辑 发表时间:2013-11-17 14:38 点击:次
很多时候我们都在为键盘遮挡了原本就不大的屏幕时而烦恼,特别是当用户处于编辑状态时,键盘下面的内容就看不见了,用户只能处于盲打状态了。现在有一种简单的解决办法,基本思路就是,添加通知。一直监听键盘事件,在键盘遮挡时,将编辑器上移键盘的高度,键盘消失时,编辑区回复原来位置,ok,来两段代码吧
[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];
[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];
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- IOS开发学习一 :Cocoa环境熟悉和Xcode使用
- ios中的银联支付
- Iphone数组一些基础操作NSArray/NSMutableArray
- ios5 编程关于@synthesize window = _window的理解
- UIButton上使用UIEdgeInsetsMaketitle跟图片对齐
- iphone的非arc形式的内存管理原理
- iPhone开发学习笔记005——使用XIB自定义一个UIVi
- ios 类文件中 ARC与非ARC的设置
- Code Sign error: The identity 'iPhone Developer' doesn't mat
- iPhone开发 对字符串进行url编码转换
新闻点评
新闻关注排行榜
热门推荐
最新推荐






![[iPhone中级]iPhone团购信息客户端的开发 (二)](/uploads/allimg/131022/200H11235-0-lp.png)



