iOS开发_UITextField视图的上升/下降 => 用协议方法控制
- 遵守代理,实现以下方法。
// 开始编辑
- (void)textFieldDidBeginEditing:(UITextField *)textField {
// 获取当前视图的 frame
CGRect frame = self.view.frame;
frame.origin.y = -53;
[UIView animateWithDuration:0.5 animations:^{
self.view.frame = frame;
}];
}
// 结束编辑
- (void)textFieldDidEndEditing:(UITextField *)textField {
CGRect frame = self.view.frame;
frame.origin.y = 0;
[UIView animateWithDuration:0.5 animations:^{
self.view.frame = frame;
}];
}