以前在iOS6中,我的聊天消息視圖控制器顯示並在IB中仔細構建的自動佈局約束正確動畫。下面是用在Xcode 5刪除約束當前視圖層次結構:iOS7問題與接口生成器生成的NSIBPrototypingLayoutConstraint自動佈局約束
升級到的XCode 5和iOS7後,我發現我需要清除,以便所有的舊約束佔默認半透明的狀態條,否則我的工具欄會在狀態欄下。儘管調用了setEdgesForExtendedLayout:使用UIRectEdgeNone,但發生了這種情況。
我現在嘗試在viewDidLoad中編程創建所有的約束:
// self.view.translatesAutoresizingMaskIntoConstraints = NO; // errors either way
NSArray *viewHorizConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_toolbar]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_toolbar)];
[self.view addConstraints:viewHorizConstraints];
viewHorizConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_viewContainer]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_viewContainer)];
[self.view addConstraints:viewHorizConstraints];
NSArray *viewVertConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(20)-[_toolbar(44)]-[_viewContainer]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_toolbar, _viewContainer)];
[self.view addConstraints:viewVertConstraints];
NSArray *tableContainerVertConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_tableView(<[email protected])][_viewInputContainer(44)]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_tableView, _viewInputContainer)];
[_viewTableContainer addConstraints:tableContainerVertConstraints];
NSArray *containerVertConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_viewTableContainer][_viewOptions]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_viewTableContainer, _viewOptions)];
[_viewContainer addConstraints:containerVertConstraints];
// _constraintContainerVertSpace = [NSLayoutConstraint constraintWithItem:_viewTableContainer attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:_viewContainer attribute:NSLayoutAttributeTrailing multiplier:1 constant:0]; // same as below
containerVertConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[_viewTableContainer]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_viewTableContainer)];
_constraintContainerVertSpace = [containerVertConstraints lastObject];
[_viewContainer addConstraint:_constraintContainerVertSpace];
containerVertConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(>=0)-[_viewOptions]-(>[email protected])-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_viewOptions)];
[_viewContainer addConstraints:containerVertConstraints];
但是,如果我試圖改變我的containerView和tableContainerView之間的垂直空間的限制,我得到的錯誤。 (我試圖調整tableContainerView與鍵盤的外觀收縮)
[UIView animateWithDuration:0.25f
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
_constraintContainerVertSpace.constant = -keyboardHeight;
} completion:nil];
這些是不能同時滿足約束條件:
(
"<NSIBPrototypingLayoutConstraint:0x140d7bb0 'IB auto generated at build time for view with fixed frame' V:|-(460)-[UIView:0x140ddef0] (Names: '|':UIView:0x140dde60)>",
"<NSIBPrototypingLayoutConstraint:0x140d7c10 'IB auto generated at build time for view with fixed frame' V:[UIView:0x140ddef0(44)]>",
"<NSLayoutConstraint:0x14d9db30 V:[UIView:0x140ddef0]-(0)-| (Names: '|':UIView:0x140dde60)>",
"<NSIBPrototypingLayoutConstraint:0x140e0290 'IB auto generated at build time for view with fixed frame' V:|-(0)-[UIView:0x140dde60] (Names: '|':UIView:0x140dddd0)>",
"<NSLayoutConstraint:0x14d9df60 V:[UIView:0x140dde60]-(-216)-| (Names: '|':UIView:0x140dddd0)>",
"<NSIBPrototypingLayoutConstraint:0x140e0830 'IB auto generated at build time for view with fixed frame' V:|-(64)-[UIView:0x140dddd0] (Names: '|':UIView:0x140e0470)>",
"<NSLayoutConstraint:0x14d9d820 V:[UIView:0x140dddd0]-(0)-| (Names: '|':UIView:0x140e0470)>",
"<NSAutoresizingMaskLayoutConstraint:0x1403a0b0 h=--& v=--& V:[UIView:0x140e0470(568)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x14d9db30 V:[UIView:0x140ddef0]-(0)-| (Names: '|':UIView:0x140dde60)>
的UIView:0x140dde60在這種情況下是_viewTableContainer。 0x140ddef0 = _viewInputContainer。 0x140dddd0 = _viewContainer。
這是爲什麼NSIBPrototypingLayoutConstraint五:| - (460) - [UIView的:0x140ddef0(_viewInputContainer)]由IB正在創建當我_viewInputContainer之間設置translatesAutoresizingMaskIntoConstraints爲NO,並且當我已經定義明確的垂直的約束和它上面的_tableView?
我已經嘗試過在樂器中使用Cocoa Layout,但是有太多的噪音讓它有任何意義。
看看這個非常類似的問題在這裏:http:// stackoverflow。com/questions/19015215/trouble-with-autolayout-on-uitableviewcell/19020006#19020006 – smileyborg