我有一个UIToolbar与GrowingTextView,一个固定的空间和一个UIBarButtonItem。看起来像:如何在更改工具栏高度时防止按钮向右移动?
当GrowingTextView library大小调整的TextView的高度约束,重新调整工具栏的高度,但也动按钮向右:
没有问题到底有多大的文本视图和按钮的位置。第一次文本视图调整大小时,它总是像20像素一样移动。只有第一次。
我该如何解决?我试过在可视化模式下编写约束,但我无法以这种方式获得这种布局。我也尝试刷新固定空间。
代码与固定空间添加一个按钮:
let item1 = UIBarButtonItem(customView: sendButton)
fixedSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.fixedSpace, target: nil, action: nil)
fixedSpace.width = UIApplication.shared.windows[0].frame.width - rightMargin - sendButton.frame.width
bottomToolbar.items = [fixedSpace, item1]
代码添加GrowingTextView:
let views: [String: Any] = ["textView": messageToSendTextView]
let hConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:|-8-[textView]-60-|", options: [], metrics: nil, views: views)
let vConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|-8-[textView]-8-|", options: [], metrics: nil, views: views)
bottomToolbar.addConstraints(hConstraints)
bottomToolbar.addConstraints(vConstraints)
self.view.layoutIfNeeded()
当你强迫/会发生什么事触发布局的观点已经出现之后? –
在你的约束中:'H:| -8- [textView] -60- |',为什么你没有任何按钮?我的意思是'H:| -8- [textView] -10- [button] -60-'' – Honey
@Honey我试过了,但显然不能这样工作。与此,你得到[这](https://www.dropbox.com/s/clpv6q3onz4o4pe/IMG_0023.PNG?dl=0)(没有文字视图) – Ivan