当我更改iOS 8中inputAccessoryView的高度时,inputAccessoryView不会转到正确的位置,而是覆盖键盘.
以下是一些代码段:
在表视图控制器中
- (UIView *)inputAccessoryView { if (!_commentInputView) { _commentInputView = [[CommentInputView alloc] initWithFrame:CGRectMake(0,[self width],41)]; [_commentInputView setPlaceholder:NSLocalizedString(@"Comment",nil) andButtonTitle:NSLocalizedString(@"Send",nil)]; [_commentInputView setBackgroundColor:[UIColor whiteColor]]; _commentInputView.hidden = YES; _commentInputView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin; } return _commentInputView; }
在CommentInputView中
#when the textview change height - (void)growingTextView:(HPGrowingTextView *)growingTextView willChangeHeight:(float)height { if (height > _textView_height) { [self setHeight:(CGRectGetHeight(self.frame) + height - _textView_height)]; [self reloadInputViews]; } }
在UIView类别从ios-helpers
- (void)setHeight: (CGFloat)heigth { CGRect frame = self.frame; frame.size.height = heigth; self.frame = frame; }
解决方法
最后,我找到了答案.在ios8中,apple将一个NSContentSizeLayoutConstraints添加到inputAccessoryView并设置一个常数为44.不能删除这个constaint,因为ios8用它来计算inputAccessoryView的高度.所以,唯一的解决办法是改变这个常数的价值.
例
在ViewDidAppear
- (void)viewDidAppear:(BOOL)animated { if ([self.inputAccessoryView constraints].count > 0) { NSLayoutConstraint *constraint = [[self.inputAccessoryView constraints] objectAtIndex:0]; constraint.constant = CommentInputViewBeginHeight; } }
当textview高度改变时,更改inputAccessoryView的高度
- (void)growingTextView:(HPGrowingTextView *)growingTextView willChangeHeight:(float)height { NSLayoutConstraint *constraint = [[self constraints] objectAtIndex:0]; float new_height = height + _textView_vertical_gaP*2; [UIView animateWithDuration:0.2 animations:^{ constraint.constant = new_height; } completion:^(BOOL finished) { [self setHeight:new_height]; [self reloadInputViews]; }]; }
那是.
原文地址:https://www.jb51.cc/iOS/336191.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。