iOS 16.0 Beta 3下UITextView固有尺寸异常问题咨询
iOS 16.0 Beta 3 实体设备上UITextView固有尺寸异常问题
在运行iOS 16.0 Beta 3(版本号20A5312j)的iPhone 12 Pro Max实体设备上,出现了UITextView固有尺寸异常的问题。该问题在运行正式版iOS 13及以上系统的其他实体设备和模拟器上均未出现。
- 左侧为预期效果,也是模拟器及非Beta版iOS设备上的实际显示效果;
- 右侧为Beta 3设备上的显示情况:顶部UITextView的固有宽度不足以容纳文本,底部UITextView的固有高度过短,无法完全显示文本。
已完成的排查步骤
- 调用
setNeedsLayout等方法无法解决问题; - 设置
contentCompressionResistancePriority为.required无任何作用; - 边框的有无不影响该问题,添加边框仅为便于观察;
- 调整
textContainerInset可正常改变内边距,但问题依然存在; - 不需要UILabel或其他替代方案(因需使用数据检测器);
- 不需要非AutoLayout的临时解决方法(如手动计算尺寸)。
我的疑问
(a) 是否遗漏了某些可避免该问题的属性设置;
(b) 其他开发者能否在Beta 3实体设备上复现该问题。若能复现,我将提交Bug报告,只想确认是否有明显遗漏。
复现代码
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 } }
内容的提问来源于stack exchange,提问作者Rob
相关产品推荐
相关产品推荐

