1
我有以下設置:iOS將視圖以編程方式自動佈局爲子視圖衝突約束
2故事板中定義的視圖控制器。
我有一個自定義的segue,通過在第一個vc上激活一個控件來觸發。
在-(void)perform
方法的segue,我不得不添加第二個vc的視圖作爲子視圖與第一個動畫。
-(void)perform{
MyVC *myVC = self.destinationViewController;
UIViewController *sourceVC = self.sourceViewController;
UIView *myView = myVC.view;
[sourceVC.view addSubview:myView];
NSDictionary *viewDictionary = NSDictionaryOfVariableBindings(sourceVC.view, drawerView);
[myView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[myView(200)]"
options:0 metrics:nil views:viewDictionary]];
}
不幸的是我得到以下錯誤。
2014-10-31 16:57:33.899 ReviewsAgain[19971:5435238] 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)
(
"<NSLayoutConstraint:0x7fb0306368c0 H:[UIView:0x7fb0306337e0(200)]>",
"<NSLayoutConstraint:0x7fb030635c80 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fb0306337e0(375)]>"
)
我相信這裏發生的一切 - myView
已應用在編譯的時候它的約束「從自己的vc`,當我把它作爲一個子視圖添加到另一個觀點 - 事情變得混亂和無法理解這就限制了應用 - 先前應用的那些 - 或我定義的那些。
我想知道解決這個問題的正確方法是什麼?