简体   繁体   English

UITextview contentSize是否自动增加?

[英]UITextview contentSize increase automatically?

I have a UITextField and UITextView in a view. 我在视图中有一个UITextFieldUITextView

The scenario is like this: 场景是这样的:

  • textFieldShouldReturn : method of the UITextField makes UITextView the firstResponder textFieldShouldReturnUITextField方法使UITextView成为firstResponder

And now the problem is , every time my textView becomes the first responder the contentSize of the UITextView increases(ie,every time the cursor moves to a new line).. 现在的问题是,每当我的textView成为第一个响应者时, UITextViewcontentSize都会增加(即,每次光标移动到新行时)。

Is there any way that the textView's contentsize remains the same??? 有什么办法可以使textView的contentsize保持不变???

Thanxx in advance.. 提前谢谢。

use this code.This will solve your problem. 使用此代码。这将解决您的问题。

-(BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        if([textField isEqual:myTextField])
        {
            [myTextField resignFirstResponder];
            [myTextView becomeFirstResponder];
            return NO;
        }
        return YES;
    }

before set contentSize use sizeToFit 在设置contentSize之前使用sizeToFit

or refer below links it will help you 或参考以下链接,它将为您提供帮助

iOS7 UITextView contentsize.height alternative iOS7 UITextView contentsize.height替代

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM