关于ios键盘遮挡输入框
2013-08-29 11:05
337 查看
方法是针对ios5.0之后键盘高度随输入法不同变化时的解决办法,同时也适用于ios5.0之前
在-(void)viewDidLoad方法里面添加通知
if(IOS_VERSION<5.0)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillHideNotification object:nil];
}else{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
至于如何获取IOS系统版本号通过如下可获取
添加一个方法-(void)keyboardWillShow:(NSNotification *)notification具体如下
-(void)keyboardWillShow:(NSNotification *)notification
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
#endif
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2
NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
#else
NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey];
#endif
CGRect keyboardBounds;
[keyboardBoundsValue getValue:&keyboardBounds];
NSInteger offset =self.view.frame.size.height-keyboardBounds.origin.y+64.0;
CGRect listFrame = CGRectMake(0, -offset, self.view.frame.size.width,self.view.frame.size.height);
NSLog(@"offset is %d",offset);
[UIView beginAnimations:@"anim" context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3];
//处理移动事件,将各视图设置最终要达到的状态
self.view.frame=listFrame;
[UIView commitAnimations];
}
}
在-(void)viewDidLoad方法里面添加通知
if(IOS_VERSION<5.0)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillHideNotification object:nil];
}else{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
至于如何获取IOS系统版本号通过如下可获取
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
添加一个方法-(void)keyboardWillShow:(NSNotification *)notification具体如下
-(void)keyboardWillShow:(NSNotification *)notification
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
#endif
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_2
NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
#else
NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey];
#endif
CGRect keyboardBounds;
[keyboardBoundsValue getValue:&keyboardBounds];
NSInteger offset =self.view.frame.size.height-keyboardBounds.origin.y+64.0;
CGRect listFrame = CGRectMake(0, -offset, self.view.frame.size.width,self.view.frame.size.height);
NSLog(@"offset is %d",offset);
[UIView beginAnimations:@"anim" context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3];
//处理移动事件,将各视图设置最终要达到的状态
self.view.frame=listFrame;
[UIView commitAnimations];
}
}
相关文章推荐
- 关于ios键盘遮挡输入框
- 关于ios键盘遮挡输入框
- iOS开发 键盘遮挡输入框(TextView、TextField)问题
- iOS个人整理07-UITextView与键盘回收与键盘遮挡输入框
- IOS开发Swift语言键盘遮挡输入框(UITextField)
- ios键盘不遮挡输入框
- iOS键盘弹出遮挡输入框问题
- iOS键盘遮挡输入框,输入区域自动上移
- iOS_开发经验总结:键盘遮挡输入框时的解决方法
- 关于IOS键盘遮住输入框以及关闭的方法。
- iOS输入框自适应键盘高度,避免遮挡
- iOS学习——键盘弹出遮挡输入框问题解决方案
- IOS学习笔记36—解决键盘遮挡输入框(UITextField)问题
- iOS解决键盘弹出遮挡输入框问题
- iOS 键盘遮挡输入框解决方案
- (iOS)关于键盘遮挡textfield问题
- 关于手机端IOS系统微信中虚拟键盘遮挡input输入框问题的解决方案
- Swift 解决IOS开发中TableView中编辑UITextField时键盘遮挡输入框的情况
- iOS 键盘遮挡输入框的解决方案
- iOS 输入框弹出键盘后改变tableView高度内容不被遮挡