ios uitextview 随输入内容增多高度增加
1个回答
2016-04-08 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
让文本框跟随键盘
我们在打开ContentView 打开键盘
然后添加键盘打开和关闭的通知,监听到通知后,调整CommentView的位置
[objc] view plain copy
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardHide:
#pragma mark keyboardNotification
-(void)keyboardShow:(NSNotification *)note
{
CGRect keyBoardRect=[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat deltaY=keyBoardRect.size.height;
[UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{
commentV.transform=CGAffineTransformMakeTranslation(0, -deltaY);
}];
}
-(void)keyboardHide:(NSNotification *)note
{
[UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{
commentV.transform=CGAffineTransformIdentity;
} completion:^(BOOL finished) {
commentV.textView.text=@"";
[commentV removeFromSuperview];
}];
}
我们在打开ContentView 打开键盘
然后添加键盘打开和关闭的通知,监听到通知后,调整CommentView的位置
[objc] view plain copy
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardHide:
#pragma mark keyboardNotification
-(void)keyboardShow:(NSNotification *)note
{
CGRect keyBoardRect=[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat deltaY=keyBoardRect.size.height;
[UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{
commentV.transform=CGAffineTransformMakeTranslation(0, -deltaY);
}];
}
-(void)keyboardHide:(NSNotification *)note
{
[UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{
commentV.transform=CGAffineTransformIdentity;
} completion:^(BOOL finished) {
commentV.textView.text=@"";
[commentV removeFromSuperview];
}];
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |