0
我在XIB中添加了1個視圖,它被設置爲自動佈局。但是當運行時,我想改變那個視圖的框架。我知道如果使用自動佈局,需要在我的代碼中設置translatesAutoresizingMaskIntoConstraints = YES
。我這樣做,我該視圖中創建新的框架,但它顯示在控制檯的警告消息:如何更改uiview的框架是在iOS中使用自動佈局?
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)
(
"<NSIBPrototypingLayoutConstraint:0x16e4b750 'IB auto generated at build time for view with fixed frame' V:|-(0)-[UIView:0x16ed3c30] (Names: '|':UIView:0x16ee06b0)>",
"<NSAutoresizingMaskLayoutConstraint:0x16e19e30 h=-&- v=-&- UIView:0x16ed3c30.midY == UIView:0x16ee06b0.midY + 44>",
"<NSAutoresizingMaskLayoutConstraint:0x16e19e60 h=-&- v=-&- UIView:0x16ed3c30.height == UIView:0x16ee06b0.height>"
)
Will attempt to recover by breaking constraint
<NSIBPrototypingLayoutConstraint:0x16e4b750 'IB auto generated at build time for view with fixed frame' V:|-(0)-[UIView:0x16ed3c30] (Names: '|':UIView:0x16ee06b0)>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
這是創造新的幀的代碼,我只想Y的原點等於0
self.leftView.frame= CGRectMake(0, 0, 40, self.view.frame.size.height);
我該如何解決這個錯誤?請給點建議。非常感謝。
謝謝,但它不能正常工作。我試過你的代碼,但它仍然顯示該警告。 – user3214941
您是否有額外的XIB文件約束衝突? – Zhang