键盘上移问题

1、输入框监听UIControlEventEditingDidBegin事件,当用户开始输入时,将整个view上移。

输入框监听UIControlEventEditingDidEnd事件,当用户结束输入时,将整个view下移,恢复到原位置。

[textfield addTarget:self action:@selector(textFieldDidBeginEditing:) forControlEvents:UIControlEventEditingDidBegin];

[textfield addTarget:self action:@selector(textFieldDidEndEditing:) forControlEvents:UIControlEventEditingDidEnd];

通过tag值来确定每个textfield是否响应

2//键盘监听

[[NSNotificationCenter

defaultCenter] addObserver:self

selector:@selector(keyboardWillChangeFrame:)

name:UIKeyboardWillChangeFrameNotification object:nil];

- (void)keyboardWillChangeFrame:(NSNotification *)notification

{

CGRect isUpflag;

[[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] getValue:&isUpflag];

NSDictionary *info = [notification userInfo];

CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

[UIView animateWithDuration:0.25 animations:^{

showView.center = CGPointMake(showView.center.x, self.view.center.y - kbSize.height);

}];

}

kbSize.height可以获取键盘的高度

原文地址 :http://blog.csdn.net/pzhtpf/article/details/9857857

你可能感兴趣的:(键盘上移问题)