我正在尝试使用自动布局约束来实现动态布局;为此我创建了3个容器视图。第一个是49高度,宽度灵活。第二个是320高度和320宽度,最后一个是69高度柔性宽度。所以这里的代码应该是将每个视图放在另一个视图之下。
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(searchControlsView, workArtView, playBackControlsContainer);
// Position time search controls
constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|[searchControlsView]|"
options:0
metrics:nil
views:viewsDictionary];
[self.view addConstraints:constraints];
constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[searchControlsView]"
options:0
metrics:nil
views:viewsDictionary];
[self.view addConstraints:constraints];
// position workArt
constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|[workArtView]|"
options:0
metrics:nil
views:viewsDictionary];
[self.view addConstraints:constraints];
constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[searchControlsView]-0-[workArtView]"
options:0
metrics:nil
views:viewsDictionary];
[self.view addConstraints:constraints];
// position bottom controls
constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"|[playBackControlsContainer]|"
options:0
metrics:nil
views:viewsDictionary];
[self.view addConstraints:constraints];
constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[workArtView]-(>=0)-[playBackControlsContainer]|" options:0 metrics:nil views:viewsDictionary];
[self.view addConstraints:constraints];
我想要实现的是最后一个视图低于第二个视图如果可能,如果不是,第三个视图将在整个屏幕的底部对齐并与第二个视图重叠。但是,第三个视图(playBackControlsContainer)未显示在屏幕中。
在此之前,我从视图中删除了所有约束。我尝试了几件事,但我只是从编程约束开始,我无法意识到我失败的地方......除了调试日志有很多额外的视图,没有和每个控件的地址的标识符,它真的很难计算我的布局可能含糊不清的原因。这是调试日志,以防万一。
*<UIWindow:0xc1a6510> - AMBIGUOUS LAYOUT
| *<UILayoutContainerView:0xc1b6b50>
| | *<UITransitionView:0xc1a3da0>
| | | *<UIViewControllerWrapperView:0xc3b82b0>
| | | | *<UIView:0xc1b9830>
| | | | | *<UILayoutContainerView:0xc1ba6a0>
| | | | | | *<UINavigationTransitionView:0xc1bf490>
| | | | | | | *<UIViewControllerWrapperView:0xc1c5110>
| | | | | | | | *<UIView:0xb478820> - AMBIGUOUS LAYOUT
| | | | | | | | | *<UIView:0xb4f9d70> - AMBIGUOUS LAYOUT
| | | | | | | | | | *<UIButton:0xb4f3e40>
| | | | | | | | | | | <UIImageView:0xc4e7030>
| | | | | | | | | | *<UIButton:0xb4f5440>
| | | | | | | | | | | <UIImageView:0xc14b0a0>
| | | | | | | | | | | *<UIButtonLabel:0xb4fb610> - AMBIGUOUS LAYOUT
| | | | | | | | | | *<UIButton:0xb4f0e80>
| | | | | | | | | | | <UIImageView:0xc1f00b0>
| | | | | | | | | | | *<UIButtonLabel:0xb4fac70> - AMBIGUOUS LAYOUT
| | | | | | | | | | *<UIButton:0xb4f04f0>
| | | | | | | | | | | <UIImageView:0xc129480>
| | | | | | | | | | | *<UIButtonLabel:0xb4fa2e0> - AMBIGUOUS LAYOUT
| | | | | | | | | *<UIView:0xb478790>
| | | | | | | | | | *<UIImageView:0xb4f9b60>
| | | | | | | | | | *<LVStopWatchLabel:0xb479200>
| | | | | | | | | | | <UIImageView:0xb478920>
| | | | | | | | | *<UIView:0xb479940>
| | | | | | | | | | *<UIButton:0xb4f6ab0>
| | | | | | | | | | | <UIImageView:0xc4e6c00>
| | | | | | | | | | *<UILabel:0xb479db0>
| | | | | | | | | | *<UISlider:0xb4f5e90>
| | | | | | | | | | | <UIView:0xc4e05e0>
| | | | | | | | | | | | <UIView:0xc4e0760>
| | | | | | | | | | | | | <UIView:0xc4e0880>
| | | | | | | | | | | | <UIView:0xc4e5c40>
| | | | | | | | | | | <UIImageView:0xc4e67d0>
| | | | | | | | | | | | <UIImageView:0xc4e5d40>
| | | | | | | | | *<_UILayoutGuide:0xb478440> - AMBIGUOUS LAYOUT
| | | | | | | | | *<_UILayoutGuide:0xb4782a0> - AMBIGUOUS LAYOUT
| | | | | | <UINavigationBar:0xc1c4a10>
| | | | | | | <_UINavigationBarBackground:0xc1c7530>
| | | | | | | | <UIImageView:0xc1c7810>
| | | | | | | <UINavigationItemView:0xc4cf610>
| | | | | | | | <UILabel:0xc4dcae0>
| | | | | | | <UINavigationItemButtonView:0xc4dcf10>
| | | | | | | | <UILabel:0xc4dcfe0>
| | | | | | | <_UINavigationBarBackIndicatorView:0xc3c3880>
| | | | | <GADBannerView:0xc3de310>
| | | | | | <GADWebView:0xc3de440>
| | | | | | | <_UIWebViewScrollView:0xc3e01a0>
| | | | | | | | <UIWebBrowserView:0xd280600>
| | | | | <ADBannerView:0xc19ad20>
| | | | | | <ADRemoteView:0xc19cca0>
| | | | | | <UIView:0xc19d590>
| | <UITabBar:0xb4a47e0>
| | | <_UITabBarBackgroundView:0xc47db60>
| | | | <_UIBackdropView:0xc47d240>
| | | | | <_UIBackdropEffectView:0xc47e490>
| | | | | <UIView:0xc47e530>
| | | <UITabBarButton:0xc19ed40>
| | | | <UITabBarSwappableImageView:0xc17ee00>
| | | | <UITabBarButtonLabel:0xc19f170>
| | | <UITabBarButton:0xc1a4120>
| | | | <UITabBarSwappableImageView:0xc1a3570>
| | | | <UITabBarButtonLabel:0xc1a3e60>
| | | <UITabBarButton:0xc1a62b0>
| | | | <UITabBarSwappableImageView:0xc1a6660>
| | | | <UITabBarButtonLabel:0xc1a6390>
| | | <UITabBarButton:0xc1a8a30>
| | | | <UITabBarSwappableImageView:0xc1a9080>
| | | | <UITabBarButtonLabel:0xc1a8f60>
| | | <UIImageView:0xc47ead0>
任何帮助找出可能是什么原因我都会非常感激。 感谢。
答案 0 :(得分:0)
我认为你忘了设定观点的高度。
例如,
constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[searchControlsView(49)]" options:0 metrics:nil views:viewsDictionary];