Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITextView文本正在开箱即用_Ios_Swift_Ios8_Uitextfield_Ios Autolayout - Fatal编程技术网

Ios UITextView文本正在开箱即用

Ios UITextView文本正在开箱即用,ios,swift,ios8,uitextfield,ios-autolayout,Ios,Swift,Ios8,Uitextfield,Ios Autolayout,我正在开发一个聊天应用程序。消息框会根据文本的长度调整大小,但换行时文本会从框中消失 我尝试在textViewDidChange方法中添加textView.contentInset=UIEdgeInsetsZero,但仍然不起作用 职能: func textViewDidChange(textView: UITextView) { let minSize = CGFloat(50) let maxSize = UIScreen.mainScreen().bounds.heig

我正在开发一个聊天应用程序。消息框会根据文本的长度调整大小,但换行时文本会从框中消失

我尝试在
textViewDidChange
方法中添加
textView.contentInset=UIEdgeInsetsZero
,但仍然不起作用

职能:

func textViewDidChange(textView: UITextView) {

    let minSize = CGFloat(50)
    let maxSize = UIScreen.mainScreen().bounds.height - 50 - keyboardHeight
    let expectedSize = textView.contentSize.height + 9

    var newSize = expectedSize < minSize ? minSize : expectedSize
    newSize = newSize > maxSize ? maxSize : newSize

    acessoryViewH.constant = newSize

    textView.contentInset = UIEdgeInsetsZero
}
func textViewDidChange(textView:UITextView){
让minSize=CGFloat(50)
设maxSize=UIScreen.mainScreen().bounds.height-50-键盘高度
让expectedSize=textView.contentSize.height+9
var newSize=expectedSizemaxSize?maxSize:newSize
acessoryViewH.constant=新闻大小
textView.contentInset=UIEdgeInsetsZero
}
自动布局约束:


尝试添加
textView.layer.masksToBounds=true
尝试设置
textView.clipsToBounds=true
在textViewDidBeginEditing委托中添加此代码。这是我的工作

textView.contentInset = UIEdgeInsetsZero;
在viewDidload中

[textView setClipsToBounds:YES];

对不起,我已经编辑了答案。当然是
masksToBounds
。谢谢,这部分是正确的,但现在不是文本开箱,而是带有顶部剪切。这是当前的viewDidLoad方法