2015年(3)
分类: iOS平台
2015-08-13 10:48:05
退回输入键盘
- (BOOL) textFieldShouldReturn:(id)textField{
[textField resignFirstResponder];
}
键盘覆盖输入框
当键盘调出时将输入框覆盖时,可以用下方法:
-
(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[self.view setFrame:CGRectMake(0, -100,
375, 667) ];
return YES;
}
-
(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
[self.view setFrame:CGRectMake(0, 0, 375, 667)];
return YES;
}
当准备输入时,将视图的位置上调100,这样键盘就不能覆盖到输入框。
// NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
// [center addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil];
// [center addObserver:self selector:@selector(keyboardHidden:) name:UIKeyboardWillHideNotification object:nil];
//
//}
//
//#pragma mark ** 回收键盘
//- (BOOL)textFieldShouldReturn:(UITextField *)textField
//{
// NSLog(@"点击回车");
//
// [textField resignFirstResponder];
//
// return YES;
//
//}
//
//- (void)keyboardHidden:(NSNotification *)notification
//{
// __block CGRect frame = self.view.frame;
// [UITextField animateWithDuration:0.25 animations:^{
//
// self.view.frame = CGRectMake(0,0, frame.size.width, frame.size.height);
//
// }];
//}
//
//- (void)keyboardShow:(NSNotification *)notification
//{
//
// NSLog(@"%@",notification);
//
// NSValue *value = [notification.userInfo objectForKey:@"UIKeyboardFrameEndUserInfoKey"];
//
// CGRect rect = [value CGRectValue];
// __block CGRect frame = self.view.frame;
// if (self.height > rect.origin.y) {
// __block int y = self.height - rect.origin.y;
// [UITextField animateWithDuration:0.25 animations:^{
//
// self.view.frame = CGRectMake(0, -y - 10, frame.size.width, frame.size.height);
//
// }];
// }
//}
//
//- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
//{
//
// NSLog(@"%@",textField);
// NSLog(@"%@",textField.superview);
//
// self.height = textField.frame.size.height + textField.frame.origin.y + textField.superview.frame.origin.y;
//
// return YES;
//}
//观察者设置键盘覆盖面