2

我有一个包含许多其他子视图的视图。它包含一个具有动态高度的 UIWebView 和几个垂直固定在一起的视图,每个部分大约 10 像素。

我正在尝试像这样设置超级视图的约束(detailsContainer):

NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self.detailsContainerView
                                                 attribute:NSLayoutAttributeHeight
                                                 relatedBy:NSLayoutRelationEqual
                                                    toItem:nil
                                                 attribute:NSLayoutAttributeNotAnAttribute
                                                multiplier:1.0
                                                  constant:9000];
heightConstraint.priority = UILayoutPriorityRequired;
[self.detailsContainerView addConstraint:heightConstraint];

然而,尽管其他一切都正确定位,但它似乎没有正确调整大小(此处使用 9000 作为实验)。由于某种原因,子视图被切断(clipToBounds 设置为 NO)。

我认为可能还有其他东西改变了这个视图的高度(虽然,我在调试器中没有看到任何破坏性约束)。

这是一个痕迹

[[UIWindow keyWindow] _autolayoutTrace]

*<UIWindow:0xcd9fd90> - AMBIGUOUS LAYOUT
    |   *<UILayoutContainerView:0x133834c0>
    |   |   *<UINavigationTransitionView:0x133847c0>
    |   |   |   *<UIViewControllerWrapperView:0x14597730>
    |   |   |   |   *<UIView:0x1339dbc0>
    |   |   |   |   |   *<UIScrollView:0x1339ce20>
    |   |   |   |   |   |   *<PNDetailsContainerView:0x1339c9f0>
    |   |   |   |   |   |   |   *<PNProductDetailsContent:0x1339c5c0>
    |   |   |   |   |   |   |   |   *<UIView:0x133bb8b0>
    |   |   |   |   |   |   |   |   |   *<UIScrollView:0x133a4be0>
    |   |   |   |   |   |   |   |   |   |   *<UIView:0x133a4db0>
    |   |   |   |   |   |   |   |   |   |   |   <_UIPageViewControllerContentView:0xcb408f0>
    |   |   |   |   |   |   |   |   |   |   |   |   <_UIQueuingScrollView:0x122a4a00>
    |   |   |   |   |   |   |   |   |   |   |   |   |   <UIView:0x10e88720>
    |   |   |   |   |   |   |   |   |   |   |   |   |   <UIView:0x10e887d0>
    |   |   |   |   |   |   |   |   |   |   |   |   |   |   <UIView:0xcb406a0>
    |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   <UIImageView:0x10e81870>
    |   |   |   |   |   |   |   |   |   |   |   |   |   <UIView:0x10e88860>
    |   |   |   |   |   |   |   |   |   |   <UIImageView:0x133a51f0>
    |   |   |   |   |   |   |   |   |   |   <UIImageView:0x133a5390>
    |   |   |   |   |   |   |   |   |   *<PNDetailsContainerView:0x133b5100>
    |   |   |   |   |   |   |   |   |   |   *<UIView:0x133b52f0> - AMBIGUOUS LAYOUT
    |   |   |   |   |   |   |   |   |   |   |   *<UILabel:0x133b5380>
    |   |   |   |   |   |   |   |   |   |   |   *<UILabel:0x133b5af0>
    |   |   |   |   |   |   |   |   |   |   |   *<UILabel:0x133b5e10>
    |   |   |   |   |   |   |   |   |   |   |   *<UILabel:0x133b65b0>
    |   |   |   |   |   |   |   |   |   |   |   *<UIImageView:0x13350be0>
    |   |   |   |   |   |   |   |   |   |   |   *<UIPageControl:0x133b7550>
    |   |   |   |   |   |   |   |   |   |   |   |   <UIView:0x145a3610>
    |   |   |   |   |   |   |   |   |   |   |   |   <UIView:0x145a3830>
    |   |   |   |   |   |   |   |   |   |   |   |   <UIView:0x145a3a30>
    |   |   |   |   |   |   |   |   |   |   |   |   <UIView:0x10e890a0>
    |   |   |   |   |   |   |   |   |   |   *<PNDescriptionWebView:0x133a7410>
    |   |   |   |   |   |   |   |   |   |   |   <_UIWebViewScrollView:0x133af740>
    |   |   |   |   |   |   |   |   |   |   |   |   <UIWebBrowserView:0xd3fc800>
    |   |   |   |   |   |   |   |   |   |   *<UIView:0x133bab70> - AMBIGUOUS LAYOUT
    |   |   |   |   |   |   |   |   |   |   |   *<UILabel:0x133bad40>
    |   |   |   |   |   |   |   |   |   |   |   *<UIImageView:0x133bb0e0>
    |   |   |   |   |   |   |   |   |   |   |   *<UIButton:0x133a18b0>
    |   |   |   |   |   |   |   |   |   |   |   |   <UIImageView:0x133a1a70>
    |   |   |   |   |   |   |   |   |   |   |   |   <UIImageView:0xe85dd80>
    |   |   |   |   |   |   |   |   |   |   |   *<UITextView:0xd3dec00>
    |   |   |   |   |   |   |   |   |   |   |   |   <_UITextContainerView:0x133c7ce0>
    |   |   |   |   |   |   |   |   |   |   |   |   <UIImageView:0x133bbd90>
    |   |   |   |   |   |   |   |   |   |   |   |   <UIImageView:0x133bbf60>
    |   |   |   |   |   |   |   |   |   |   *<UIView:0x133a4200> - AMBIGUOUS LAYOUT
    |   |   |   |   |   |   |   |   |   |   |   *<UIScrollView:0x133a4290>
    |   |   |   |   |   |   |   |   |   |   |   |   *<PNColorSizeButton:0x144c3b00> - AMBIGUOUS LAYOUT
    |   |   |   |   |   |   |   |   |   |   |   |   |   <UIButtonLabel:0x144c3bf0>
    |   |   |   |   |   |   |   |   |   |   |   |   *<PNColorSizeButton:0x144c4f20> - AMBIGUOUS LAYOUT
    |   |   |   |   |   |   |   |   |   |   |   |   |   <UIButtonLabel:0x144c5010>
    |   |   |   |   |   |   |   |   |   |   |   |   *<PNColorSizeButton:0x144c6330> - AMBIGUOUS LAYOUT
    |   |   |   |   |   |   |   |   |   |   |   |   |   <UIButtonLabel:0x144c6420>
    |   |   |   |   |   |   |   |   |   |   |   |   *<PNColorSizeButton:0x144c7720> - AMBIGUOUS LAYOUT
    |   |   |   |   |   |   |   |   |   |   |   |   |   <UIButtonLabel:0x144c7810>
    |   |   |   |   |   |   |   |   |   |   |   |   *<PNColorSizeButton:0x144c8b10> - AMBIGUOUS LAYOUT
    |   |   |   |   |   |   |   |   |   |   |   |   |   <UIButtonLabel:0x144c8c00>
    |   |   |   |   |   |   |   |   |   |   |   *<UIScrollView:0x133a3ca0>
    |   |   |   |   |   |   |   |   |   |   |   |   *<PNColorSizeButton:0xe8445b0> - AMBIGUOUS LAYOUT
    |   |   |   |   |   |   |   |   |   |   |   |   |   <UIButtonLabel:0xe844850>
    |   |   |   |   |   |   |   |   |   |   |   |   *<PNColorSizeButton:0xe84a290> - AMBIGUOUS LAYOUT
    |   |   |   |   |   |   |   |   |   |   |   |   |   <UIButtonLabel:0xe84a380>
    |   |   |   |   |   |   |   |   |   |   |   |   *<PNColorSizeButton:0xe84f7d0> - AMBIGUOUS LAYOUT
    |   |   |   |   |   |   |   |   |   |   |   |   |   <UIButtonLabel:0xe84f8c0>
    |   |   |   |   |   |   |   |   |   |   |   *<UIButton:0x133a35a0>
    |   |   |   |   |   |   |   |   |   |   |   |   <UIButtonLabel:0xe85bcf0>
    |   |   |   |   |   |   |   |   |   |   *<UIView:0x133a37b0> - AMBIGUOUS LAYOUT
    |   |   |   |   |   |   |   |   |   |   |   *<UIButton:0x133a13d0>
    |   |   |   |   |   |   |   |   |   |   |   |   <UIButtonLabel:0xe85ae50>
    |   |   |   |   |   |   |   |   |   |   |   *<UIButton:0x133a2f40>
    |   |   |   |   |   |   |   |   |   |   |   |   <UIButtonLabel:0xe859ce0>
    |   |   |   |   |   |   <UIImageView:0x145975a0>
    |   |   |   |   |   *<UIButton:0x1339dc50>
    |   |   |   |   |   |   <UIButtonLabel:0xe858c70>
    |   |   |   |   |   *<_UILayoutGuide:0x1339e720> - AMBIGUOUS LAYOUT
    |   |   |   |   |   *<_UILayoutGuide:0x1339ec50> - AMBIGUOUS LAYOUT
    |   |   <UINavigationBar:0x10b524b0>
    |   |   |   <_UINavigationBarBackground:0xe9bcad0>
    |   |   |   |   <_UIBackdropView:0x133835d0>
    |   |   |   |   |   <_UIBackdropEffectView:0x133839d0>
    |   |   |   |   |   <UIView:0x13383a70>
    |   |   |   |   <UIImageView:0xe9bcbb0>
    |   |   |   <UINavigationItemView:0x10b52c90>
    |   |   |   |   <UILabel:0x10b52d40>
    |   |   |   <UINavigationButton:0xbf0b790>
    |   |   |   |   <UIButtonLabel:0xbf0b490>
    |   |   |   <UINavigationButton:0xbf0a370>
    |   |   |   |   <UIImageView:0xbf09d10>
    |   |   |   <_UINavigationBarBackIndicatorView:0x133983e0>

我很想解决这个问题,所以 detailsContainerView 是实际大小。

可能需要注意的是,整个视图正在作为子视图加载到属于滚动视图的另一个视图中。我可以手动设置 contentSize 以及视图的高度,只是 detailViewController 似乎不想采用 9000 高度(或者其他原因可能是罪魁祸首)。

4

0 回答 0