我不能再在rightView 13上使用MDCTextField的MDCTextField属性了,难道只有我有这个问题吗?
正确的视图宽度覆盖整个文本字段:防止用户交互和隐藏textView内容。
当我从MDCTextField切换到UITextField时没有问题。
发布于 2019-09-30 20:04:11
将宽度 constraint添加到rightView/leftView。
别忘了设置translatesAutoresizingMaskIntoConstraints = false
rightView.translatesAutoresizingMaskIntoConstraints = false
rightView.widthAnchor.constraint(equalToConstant: <#NeededWidth#>).isActive = true
// This is enough to make it act like before but you can set other missing constraints like height to suppress layout warnings and prevent further issues.
// rightView.widthAnchor.constraint(equalToConstant: <#HeightOfTheTextField#>).isActive = true您可能会注意到消费中的一些自动收费警告,因为您没有为rightView/leftView设置缺少的约束。因此,添加缺少的约束,或者简单地忽略这些约束。
请注意,如果rightView/leftView是某种StackView,请尝试将其放入view中,然后添加此视图。
发布于 2019-09-27 13:40:39
显然,这改变了rightViewRect(forBounds:)在iOS 13 Beta 5中的行为方式。
来自iOS & iPadOS 13开发人员Beta 5发行说明
UIKit -解决的问题 在iOS 13之前,UITextField假定其leftView和rightView的帧在分配时被正确设置,并且不会更改。从iOS 13开始,leftViewRect(forBounds:)和rightViewRect(forBounds:)的实现现在为其systemLayoutSizeFitting(:)询问视图。若要在iOS 13上链接和运行之前的行为,请在视图上添加显式的大小调整约束,将其包装在普通的UIView中,或将视图子类化并实现systemLayoutSizeFitting(:)。(51787798)
需要更新MDCTextField -(CGRect)rightViewRectForBounds:(CGRect)bounds函数。
https://stackoverflow.com/questions/58078320
复制相似问题