gpt4 book ai didi

ios - 更改 inputAccessoryView 问题的高度

转载 作者:IT王子 更新时间:2023-10-29 08:14:35 24 4
gpt4 key购买 nike

当我在 iOS 8 中更改 inputAccessoryView 的高度时,inputAccessoryView 没有转到正确的原点,而是覆盖了键盘。

enter image description here

下面是一些代码片段:

在 TableView Controller 中

- (UIView *)inputAccessoryView {
if (!_commentInputView) {
_commentInputView = [[CommentInputView alloc] initWithFrame:CGRectMake(0, 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];
}
}

在来自 ios-helpers 的 UIView 类别中

- (void)setHeight: (CGFloat)heigth {
CGRect frame = self.frame;
frame.size.height = heigth;
self.frame = frame;
}

最佳答案

终于,我找到了答案。在ios8中,apple给inputAccessoryView增加了一个NSContentSizeLayoutConstraints,并设置了一个常量44。你不能去掉这个constant,因为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];
}];
}

也就是。

关于ios - 更改 inputAccessoryView 问题的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27419774/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com