UITextView失去了高度

时间:2015-12-10 22:56:19

标签: ios size uitextview

我有简单的textview和动态高度,因为我希望它符合它的内容。但每次当我完成文本输入并再次开始操作时,textview会失去他的高度并回到初始高度。是的,我是iOS开发的新手。这是我的代码

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

if ([text isEqualToString:@"\n"]) {
    [textView endEditing:true];
    return false;
}

return true; 
}


-(void)textViewDidChange:(UITextView *)textView{

    self.myTextView.text = self.myTextView.text.uppercaseString;

    int lines = self.myTextView.contentSize.height / self.myTextView.font.lineHeight;
    NSLog(@"number of lines: %d", lines);

    if (lines >=2) {

        if (lines != optionLineChek) {

            CGSize size = [self.myTextView systemLayoutSizeFittingSize:self.myTextView.contentSize];
            CGRect frame = self.myTextView.frame;
            frame.size.height = size.height;
            self.myTextView.frame = frame;

        }

    } 
 }

the problem

0 个答案:

没有答案