CSGrowingTextView 是一个 iOS 文本视图,在用户输入时使用键盘自动调整大小。
您可以使用代码或 Interface Builder,带有或没有自动布局来使用它。使用 growDirection 来控制 CSGrowingTextView 应该在哪个方向上增长,使用 growAnimationDuration 和 growAnimationOptions 属性来调整增长动画。
如果您想实现自己的增长动画,实现 CSGrowingTextViewDelegate 的 growingTextView:willChangeHeight 方法,并按照以下方式提交动画:
// This example uses autolayout
- (void)growingTextView:(CSGrowingTextView *)growingTextView willChangeHeight:(CGFloat)height {
__weak id this = self;
[UIView animateWithDuration:0.25
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
__strong CSKeyboardViewController *strongThis = this;
strongThis.growingTextViewHeightConstraint.constant = height;
[strongThis.growingTextView setNeedsUpdateConstraints];
[strongThis.growingTextView.superview layoutIfNeeded];
} completion:nil];
}
platform :ios, '6.0'
pod 'CSGrowingTextView', '~> 1.0'