創建視圖無法同時滿足約束條件時,圖幅爲零
init(){
super.init(frame: .zero)
}
創建視圖我想設置我的子視圖
func setViews(){
self.addSubview(labelView)
self.addConstraintsWithFormat("V:|-10-[v0]-10-|", views: labelView)
self.addConstraintsWithFormat("H:|-10-[v0]-10-|", views: labelView)
}
一切正常後,但我已經警告說,
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)
(
"<NSLayoutConstraint:0x7f87ea8e6520 V:|-(10)-[BIPartners.labelView:0x7f87eb56be20] (Names: '|':BIPartners.labelView:0x7f87eb56a320)>",
"<NSLayoutConstraint:0x7f87ea8e6af0 V:[BIPartners.labelView:0x7f87eb56be20]-(10)-| (Names: '|':BIPartners.labelView:0x7f87eb56a320)>",
"<NSLayoutConstraint:0x7f87e868bdc0 '_UITemporaryLayoutHeight' V:[BIPartners.labelView:0x7f87eb56a320(0)]>"
)
我知道這個問題是當我將幀設置爲零。我將幀設置爲零,並將垂直邊距設置爲10.我應該如何解決此問題?
你和VFL結婚了嗎?在堆棧視圖或其他內容中執行此操作可能會更容易,並隱藏/取消隱藏所需的元素,這樣您就不會對約束進行記錄。 – Adrian