iOS(编辑内容被键盘遮盖)ScrollView里的包含了TextField&&TextView(用了监听的方法)

dMdM~ 2015-11-16 03:18:42
现在ScrollView里的TextField编辑弹出键盘,ScrollView上移的特效做好,可是TextView按照TextField的方法却没有效果(下面写出了TextField的方法,急需TextView编辑ScrollView上移到可显示位置的方法!!!)
【TextField】

- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];

}

// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height + 70, 0.0);
_myScroolView.contentInset = contentInsets;
_myScroolView.scrollIndicatorInsets = contentInsets;

// If active text field is hidden by keyboard, scroll it so it's visible
// Your application might not need or want this behavior.

CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;

// if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) {
// CGPoint scrollPoint = CGPointMake(0.0, activeField.frame.origin.y-kbSize.height);
// [_myScroolView setContentOffset:scrollPoint animated:YES];
// }

}

// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
_myScroolView.contentInset = contentInsets;
_myScroolView.scrollIndicatorInsets = contentInsets;
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];

return YES;
}

【TextView】???????????????????????????????????? 大神指点下~
...全文
519 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sailip 2016-10-21
  • 打赏
  • 举报
回复
IQKeyboardManager 这个第三方键盘监听完美解决所有遮挡问题
L_Sovereign 2016-10-19
  • 打赏
  • 举报
回复
谢谢楼主贴出了TextField的解决办法
  • 打赏
  • 举报
回复
我对为是分享呢,错了。
dMdM~ 2015-11-17
  • 打赏
  • 举报
回复
无人解答麽?

29,049

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧