UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 220* 2, 30)];
在 - (void)viewDidLoad写下面的代码
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillshow) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil]; } -(void)keyboardWillshow {
[UIView animateWithDuration:0.2 animations:^{
_butn.frame = CGRectMake(20, 20, 200, 20);
//这里写butn要改变的位置
} completion:^(BOOL finished) {
}];
}
-(void)keyboardWillHide {
[UIView animateWithDuration:0.2 animations:^{
_butn.frame = CGRectMake(20, 20, 200, 20);//这里写butn刚开始定义的原位置 } completion:^(BOOL finished) {
}];
}
}