Objective-c – 由Interface Builder生成的NSIBPrototypingLayoutConstraint autolayout约束的iOS7问题

前端之家收集整理的这篇文章主要介绍了Objective-c – 由Interface Builder生成的NSIBPrototypingLayoutConstraint autolayout约束的iOS7问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
以前在iOS6中,我的聊天消息视图控制器显示和动画正确,在IB中精心构造的自动布局约束.以下是 Xcode 5中删除约束的当前视图层次结构: @H_404_2@升级到XCode 5和iOS7后,我发现我需要清除所有旧的限制,以便考虑默认的半透明状态栏,否则我的工具栏将落在状态栏下.尽管调用setEdgesForExtendedLayout:与UIRectEdgeNone无关.

@H_404_2@我现在试图在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(<=460@999)][_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]-(>=-216@999)-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_viewOptions)];
[_viewContainer addConstraints:containerVertConstraints];
@H_404_2@但是,如果我尝试更改我的containerView和tableContainerView之间的垂直空间约束,我会收到错误. (我正在尝试调整tableContainerView的大小以缩小与键盘的外观.)

[UIView animateWithDuration:0.25f
                      delay:0
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     _constraintContainerVertSpace.constant = -keyboardHeight;
                 } completion:nil];
@H_404_2@这些是不能同时满足的约束:

(
"<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 )>
@H_404_2@UIView:0x140dde60在这种情况下是_viewTableContainer. 0x140ddef0 = _viewInputContainer. 0x140dddd0 = _viewContainer.

@H_404_2@为什么当我设置将AutotoresizingMaskIntoConstraints转换为NO时,由IB创建的NSIBPrototypingLayoutConstraint V:| – (460) – [UIView:0x140ddef0(_viewInputContainer)],当我已经在_viewInputContainer和上面的_tableView之间定义了明确的垂直约束?

@H_404_2@我尝试在乐器中使用可可版面,但是有太多的噪音,无法理解它.

解决方法

除了使用translateAutoresizingMaskIntoConstraints之外,我不得不手动删除视图上的约束.
[_viewContainer removeConstraints:_viewContainer.constraints];
[self.view removeConstraints:self.view.constraints];
@H_404_2@添加这些更改后,动画没有更多的错误.

原文链接:https://www.f2er.com/c/113970.html

猜你在找的C&C++相关文章