也许问题的根源在于我,但我找不到禁用自动滚动的scrollview选项textView里面
每当用户在滚动视图的可见区域底部输入新行并继续输入时,滚动视图就会随之移动
——————
这不是问题,问题是我不能为它设置一个“边距”,以防止 UI 元素看起来过于拥挤
图片:
(1) 现在在底部输入新行并键入 / 滚动视图自动滚动到该位置 /
(2) 它应该是什么样子
我能做什么?
也许问题的根源在于我,但我找不到禁用自动滚动的scrollview选项textView里面
每当用户在滚动视图的可见区域底部输入新行并继续输入时,滚动视图就会随之移动
——————
这不是问题,问题是我不能为它设置一个“边距”,以防止 UI 元素看起来过于拥挤
图片:
(1) 现在在底部输入新行并键入 / 滚动视图自动滚动到该位置 /
(2) 它应该是什么样子
我能做什么?
我正在用 UITextView 做类似的事情,它有一个指定的初始高度,并不断增加输入文本的高度,直到达到最大指定高度,然后开始滚动文本。让我知道那是您正在寻找的东西。
我正在使用如下委托方法。以下代码中的高度约束是来自 Storyboard 的 IBOutlets。
func textViewDidChange(_ textView: UITextView) {
let maxSize = CGSize(width: textView.frame.width, height: 90.0)
let estimatedSize = textView.sizeThatFits(maxSize)
if estimatedSize.height <= 90 {
textView.isScrollEnabled = false
textViewHeightConstraint.constant = estimatedSize.height
textViewContainerHeightConstraint.constant = estimatedSize.height + 12.0
} else {
textView.isScrollEnabled = false
textViewHeightConstraint.constant = 90.0
textViewContainerHeightConstraint.constant = 102.0
}
}
我有一个类似的问题。只需在其周围放置一个容器(UIView)并将 UITextView 放入此容器中。您可以通过 mytextView.superview 访问这个...
这是一个如何使用他的 Container 创建 TextView 的示例...
// SuperView of textView
let container = UIView()
self.scrollView.addSubview(container)
let textView = UITextView()
/*
your textView config
*/
container.addSubview(textView)
并且只需在 TVs 委托方法中设置一个引用(如果完成编辑,不要忘记清除它)
// Delegate of UITextView...
func textViewDidBeginEditing(_ textView: UITextView) {
activeTextView = textView
currentIdentifier = textView.accessibilityIdentifier
}
这是观察者内部的一个片段(KeyboardDidShow / Hide)
// activeTextView was defined inside textView
if activeTextView != nil {
// now you can access it via textview.superview?
if let origin = activeTextView.superview?.frame.origin, let parentFrame = activeTextView.superview?.frame {
if !aRect.contains(origin) {
scrollView.scrollRectToVisible(parentFrame, animated:true)
}
}
}
唯一的工作方法是在textView的底部添加一个视图..不太明白为什么