[英]UITextView intrinsic size problem in iOS 16.0 Beta 3
I am having trouble with an app that uses the intrinsic size of a UITextView
on a physical iPhone 12 Pro Max running iOS 16.0 beta 3 (20A5312j).我在运行 iOS 16.0 beta 3 (20A5312j) 的物理 iPhone 12 Pro Max 上使用UITextView
的固有大小的应用程序遇到问题。 It seems to work on my other physical devices running production iOS versions (iOS 13 and later).它似乎适用于我的其他运行生产 iOS 版本(iOS 13 及更高版本)的物理设备。 And it works on the simulators.它适用于模拟器。
The image on the left is what I would expect and what I am actually seeing on simulators and non-beta iOS devices.左边的图像是我所期望的,也是我在模拟器和非测试版 iOS 设备上实际看到的。 The image on the right is what I am seeing on Beta 3, with the first text view's intrinsic width not wide enough to fit the text, and the text view's intrinsic height:右边的图像是我在 Beta 3 上看到的,第一个文本视图的固有宽度不足以容纳文本,而文本视图的固有高度:
On the right, the intrinsic width of the top text field on the right image is too narrow to fit the text.在右侧,右侧图像顶部文本字段的固有宽度太窄而无法容纳文本。 The intrinsic height of the bottom text field is too short to fit the text.底部文本字段的固有高度太短,无法容纳文本。
And before people ask, a few observations:在人们问之前,有一些观察:
setNeedsLayout
(or the like) does not fix it.调用setNeedsLayout
(或类似的)并不能解决它。setContentCompressionResistancePriority
with .required
(or what have you) has no impact.用.required
(或者你有什么)调用setContentCompressionResistancePriority
没有影响。textContainerInset
adjusted the insets as expected, but manifested the same problem.调整textContainerInset
按预期调整了插图,但出现了同样的问题。UILabel
or other alternatives (as I need the data detectors).我不是在寻找UILabel
或其他替代品(因为我需要数据检测器)。The question is merely (a) whether I am missing some property that avoids manifesting this behavior, and (b) whether others can reproduce the problem on Beta 3 physical devices.问题仅仅是(a)我是否遗漏了一些可以避免表现出这种行为的属性,以及(b)其他人是否可以在 Beta 3 物理设备上重现该问题。 If others see the same behavior that I am, I am happy to file a bug report.如果其他人看到与我相同的行为,我很乐意提交错误报告。 I just want to make sure I am not overlooking anything obvious.我只是想确保我没有忽略任何明显的东西。
Here is the code that reproduced the above images:这是重现上述图像的代码:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let shortTextView = addTextView()
shortTextView.text = "foo bar baz"
let longTextView = addTextView()
longTextView.text = "This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test."
NSLayoutConstraint.activate([
shortTextView.topAnchor.constraint(equalTo: view.topAnchor, constant: 100),
longTextView.topAnchor.constraint(equalTo: shortTextView.bottomAnchor, constant: 40)
])
}
/// Add text view to main view
///
/// This:
/// 1. Creates text view (with border so we can see its `frame`);
/// 2. Adds to the main view; and
/// 3. Adds horizontal constraints (with `lessThanOrEqual` for width to take advantage of text view’s intrinsic size).
///
/// Note, even if you turn off the border, I see the same problem on physical device running iOS 16.0 Beta 3 (20A5312j).
/// But the border lets you see what's going on.
func addTextView() -> UITextView {
let textView = UITextView()
textView.translatesAutoresizingMaskIntoConstraints = false
textView.isScrollEnabled = false
textView.isEditable = false
textView.layer.borderWidth = 1
textView.layer.borderColor = UIColor.gray.cgColor
view.addSubview(textView)
let widthConstraint = NSLayoutConstraint(
item: textView,
attribute: .width,
relatedBy: .lessThanOrEqual,
toItem: view,
attribute: .width,
multiplier: 0.8,
constant: 0
)
NSLayoutConstraint.activate([
textView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
widthConstraint
])
// note, vertical constraint not yet set ... will be set by caller
return textView
}
}
While I filed a bug report (FB10884711), it would appear that this was resolved in Beta 4.虽然我提交了错误报告 (FB10884711),但似乎这已在 Beta 4 中得到解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.