C# 如何在xamarin.ios中添加新线时实现多线/自动调整大小UITextView,类似于SMS应用程序或Skype应用程序

C# 如何在xamarin.ios中添加新线时实现多线/自动调整大小UITextView,类似于SMS应用程序或Skype应用程序,c#,xamarin,xamarin.ios,C#,Xamarin,Xamarin.ios,我们正在xamarin.ios中开发一个聊天应用程序,因此在这里,我们希望在添加短信或Skype应用程序等新行时实现一个自动增长的文本视图。如何在xamarin.ios中实现这一点。我在这方面做了很多研发,在互联网上也做了很多搜索,但还没有找到合适的解决方案 请指导我解决此问题。请参阅以下代码: CGSize oldSize; public ViewController (IntPtr handle) : base (handle) { } public override void View

我们正在xamarin.ios中开发一个聊天应用程序,因此在这里,我们希望在添加短信或Skype应用程序等新行时实现一个自动增长的文本视图。如何在xamarin.ios中实现这一点。我在这方面做了很多研发,在互联网上也做了很多搜索,但还没有找到合适的解决方案


请指导我解决此问题。

请参阅以下代码:

CGSize oldSize;

public ViewController (IntPtr handle) : base (handle)
{
}

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();
    // Perform any additional setup after loading the view, typically from a nib.

    UITextView textView = new UITextView(new CGRect(20,20,100,30));
    oldSize = textView.Frame.Size;
    textView.Font = UIFont.SystemFontOfSize(16);
    textView.TextColor = UIColor.Black;
    textView.Changed += (sender, e) => {

      if(textView.Text.Length!=0&&textView.Text!="")
        {
            CGRect frame = textView.Frame;

            double newHeight = Math.Ceiling(textView.SizeThatFits(new CGSize(oldSize.Width,9999999999)).Height);

            // update the height if the newHeight larger than the old
            if(newHeight >= oldSize.Height)
             {
                textView.Frame = new CGRect(frame.X, frame.Y, frame.Size.Width, newHeight);
             }
        }   

    };
    View.AddSubview(textView);
}

嗨,我们还有另一个简单的解决方案

textview.Changed += (object sender, EventArgs e) =>
                
{
     
 //Action
                    
var NewHeight = txtMsgToSend.ContentSize.Height;
                   
textview.Frame = new CGRect(x:textview.Frame.X, y: textview.Frame.Y,  width:  
textview.Frame.Width, height: NewHeight);
                      
                    
}
    
                
};

嗨,我正在做。谢谢你的答复。。