我有在代碼插入myController的,(自=根視圖控制器)這樣:定製自動佈局約束添加控制器的視圖時破碎編程
MyViewController* myController = [[MyViewController alloc] initWithNibName:nil bundle:nil];
[self addChildViewController:myController];
[self.view addSubview:myController.view];
myController.view.frame = CGRectMake(0, 504, 320, 216);
在MyViewController的XIB文件,我只有2個視圖,一個在另一個之上。可以說頂視圖叫做View1,底視圖是View2。 View0是主視圖。
我已加入下列垂直NSLayoutConstraints: 五:[視圖2(40)] 五:| - (0)-View1(產品名稱: '|':View0) 五:View2-(0) - | (名稱:'|':View0) V:View1-(0)-View2
也就是說View1在頂部觸及View0,在底部觸摸View2。 View2在頂部觸及View1,在底部觸摸View0,並且具有40的恆定高度。
當我以縱向方式運行這個時,每件事情似乎都沒問題。但是當我旋轉到風景時,我有時會出現以下錯誤。
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:0xd17cc00 h=--& v=--& V:[UIView:0xd174a30(268)]>",
"<NSLayoutConstraint:0x9469890 V:[View2(40)]>",
"<NSLayoutConstraint:0x9468e90 V:|-(0)-View1 (Names: '|':View0)>",
"<NSLayoutConstraint:0x9468ef0 V:View2-(0)-| (Names: '|':View0)>",
"<NSLayoutConstraint:0x94676f0 V:View1-(0)-View2>",
"<NSAutoresizingMaskLayoutConstraint:0x9450640 h=-&- v=-&- UIView:0000.height == UIView:0xd174a30.height - 268>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x9469890 V:[View2(40)]>
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.
有人明白爲什麼會發生這種情況嗎?我應該怎麼做才能將我定義的約束保持爲先前的?