我有一個非常簡單的設置,我無法做到我想要的。我正在嘗試添加inputAccessoryView
。UIView的高度約束打破子視圖的高度約束
對於inputAccessoryView
我有一個UIView
(ViewA)配有一個子視圖(ViewB)。 ViewB固定爲ViewA的所有邊緣。 查看B有固定的高度,需要高度爲ViewA和ViewB。
ViewA的不是由我設定,但是0
打破ViewB(設定爲42)的高度。
ViewA被添加作爲在UIViewController
的視圖一個子視圖並固定在底部和兩個前緣和後緣(ViewA和ViewB的所以寬度應是UIViewController的視圖,其中它是)。
這裏是我的代碼:
override init(frame: CGRect) {
super.init(frame: frame)
let viewB = UIView()
addSubview(viewB)
viewB.translatesAutoresizingMaskIntoConstraints = false
viewB.topAnchor.constraint(equalTo: topAnchor).isActive = true
viewB.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
viewB.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
viewB.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
viewB.heightAnchor.constraint(equalToConstant: 42).isActive = true
}
這將導致以下錯誤:
2017-12-02 15:44:59.150228-0800 Ping[37511:5808904] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x608000283b60 h=--& v=--& MyApp.ViewA:0x7fe606511360.height == 0 (active)>",
"<NSLayoutConstraint:0x608000282030 UIView:0x7fe606511550.height == 42 (active)>",
"<NSLayoutConstraint:0x608000281d60 V:|-(0)-[UIView:0x7fe606511550] (active, names: '|':MyApp.ViewA:0x7fe606511360)>",
"<NSLayoutConstraint:0x608000281ef0 UIView:0x7fe606511550.bottom == MyApp.ViewA:0x7fe606511360.bottom (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x608000282030 UIView:0x7fe606511550.height == 42 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
ViewA有一個非常簡單的設置:
extension MessageViewController {
open override var canBecomeFirstResponder: Bool {
return true
}
open override var inputAccessoryView: UIView? {
return messageInputView
}
}
爲什麼ViewA他我從來沒有設置的ight突破了我設置的限制?
@RuslanSerebriakov我已經更新了上面的代碼 – runmad