0
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
int numLines = textView.contentSize.height/textView.font.lineHeight;
CGFloat goodHeight = BASE_COMMENT_HEIGHT + ((numLines-1) * textView.font.lineHeight);
CGFloat currentHeight = textView.frame.size.height;
CGFloat heightDiff = goodHeight - currentHeight;
if (heightDiff != 0) {
CGRect containerFrame = self.commentInputContainer.frame;
containerFrame.size.height += heightDiff;
containerFrame.origin.y -= heightDiff;
self.commentInputContainer.frame = containerFrame;
CGRect commentFrame = self.inlineCommentField.frame;
commentFrame.origin.y -= heightDiff;
commentFrame.size.height += heightDiff;
self.inlineCommentField.frame = commentFrame;
}
return YES;
}
我正在尝试动态调整注释字段的大小。当评论的行数增加时,我打算增加字段的大小和字段的容器大小。一起调整父级和子级帧的高度
但是,上面的代码的问题是,当我尝试调整父级(容器)和子级(commentField)的大小时,子级的大小不会更改。
这是怎么回事?我该如何解决这个问题?
你应该使用自动布局来改变高度,它应该容易得多。 – kientux