@interface CommentViewController ()<UITextFieldDelegate,UIGestureRecognizerDelegate>{
CGRect normalRect; //默认高度
}
//监控键盘
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBegin:) name:UIKeyboardWillShowNotification object:nil ];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyEnd:) name:UIKeyboardWillHideNotification object:nil ];
#pragma mark textField Methods-
- (void)keyBegin:(NSNotification *) notif{
CGRect keyBoardRect = [[notif.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
[UIView animateWithDuration:.3 animations:^{
self.commentView.frame = CGRectMake(self.commentView.frame.origin.x, normalRect.origin.y- keyBoardRect.size.height, self.commentView.frame.size.width,self.commentView.frame.size.height);
} completion:^(BOOL finished) {
}];
}
- (void)keyEnd:(NSNotification *) notif{
[UIView animateWithDuration:.3 animations:^{
self.commentView.frame = normalRect; //恢复默认高度
} completion:^(BOOL finished) {
}];
}
本文介绍了一种处理iOS应用中键盘弹起时调整TextField所在View高度的方法。通过监听键盘显示和隐藏通知,实现视图的高度动态调整,确保用户输入体验。
5107

被折叠的 条评论
为什么被折叠?



