【发布时间】:2015-04-20 18:03:57
【问题描述】:
我遇到的一个问题是,我想在键盘显示时将 UIView(footerview) 向上移动,并在键盘关闭时将其向下移动。
- 我的 UIView (FooterView) 包含在 Main.Storyboard 的 UIViewController 中,由 Xcode 自动生成。
- 我也有一个 TextField。
视图层次结构如下所示:
查看:
-->文本域
--> UIView(FooterView)
编辑:
在我发布这个问题后,我自己找到了答案
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
[self.view endEditing:YES];
return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
- (void)keyboardDidShow:(NSNotification *)notification
{
// Assign new frame to view
[self.footerView setFrame:CGRectMake(0,250,320,65)];
}
-(void)keyboardDidHide:(NSNotification *)notification
{
// set it back to the original place
[self.footerView setFrame:CGRectMake(0,503,320,65)];
}
【问题讨论】:
-
发布你到目前为止所尝试的内容。
-
你想在文本文件进入时向上移动视图
-
是的,我想上下移动它。
-
@vichhai 关注这些链接Autolayout 或Autolayout programatically
标签: ios uiview uikeyboard