我有一个 UIView 的问题,我添加到屏幕底部并在按下按钮时将其动画以填充大部分屏幕。视图将上下动画并按预期旋转。如果我尝试在风景中设置动画,它会中断并给我错误消息:
*** Assertion failure in -[UIScrollView _edgeExpressionInContainer:vertical:max:], /SourceCache/UIKit_Sim/UIKit-2380.17/NSLayoutConstraint_UIKitAdditions.m:2174
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Autolayout doesn't support crossing rotational bounds transforms with edge layout constraints, such as right, left, top, bottom. The offending view is: <UIView: 0x9199340; frame = (20 0; 748 1024); transform = [0, -1, 1, 0, 0, 0]; autoresize = RM+BM; layer = <CALayer: 0x91993d0>>'
有问题的视图是 self.view。
我如何创建 UIView:
[self.myContentView addSubview:subBar.filterListView];
[self.myContentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[filterListView]|"
options:0
metrics:nil
views:@{@"filterListView": subBar.filterListView}]];
subBar.filterListView.bottomConstraint = [NSLayoutConstraint constraintWithItem:subBar.filterListView
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.mapView
attribute:NSLayoutAttributeBottom
multiplier:1
constant:0];
subBar.filterListView.topConstraint = [NSLayoutConstraint constraintWithItem:subBar.filterListView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.mapView
attribute:NSLayoutAttributeBottom
multiplier:1
constant:0];
[self.myContentView addConstraint:subBar.filterListView.bottomConstraint];
[self.myContentView addConstraint:subBar.filterListView.topConstraint];
self.myContentView 是一个占据整个 self.view 的 UIView:
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contentView]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(contentView)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[contentView]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(contentView)]];
要为 subBar.filterListView 设置动画,我删除了顶部和底部约束,重新分配它们,添加它们,然后设置动画:
[self.myContentView removeConstraint:view.topConstraint];
[self.myContentView removeConstraint:view.bottomConstraint];
view.topConstraint = [NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.topToolBar
attribute:NSLayoutAttributeBottom
multiplier:1
constant:0];
view.bottomConstraint.constant -= SUB_BAR_SIZE.height;
[self.myContentView addConstraint:view.topConstraint];
[self.myContentView addConstraint:view.bottomConstraint];
[self.myContentView setNeedsUpdateConstraints];
[UIView animateWithDuration:.25 animations:^{
[self.myContentView layoutIfNeeded];
}];
代码在旋转时会与顶部和底部混淆吗?它认为肖像顶部是风景的左边吗?