Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2030
  • 博文数量: 3
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 40
  • 用 户 组: 普通用户
  • 注册时间: 2015-08-13 10:16
文章分类
文章存档

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;

//}











阅读(133) | 评论(0) | 转发(0) |
0

上一篇:UITextField小总结

下一篇:小结

给主人留下些什么吧!~~