【问题标题】:NSLayoutConstraint conflict. UIView-Encapsulated-Layout-HeightNSLayoutConstraint 冲突。 UIView-Encapsulated-Layout-Height
【发布时间】:2015-05-20 10:44:10
【问题描述】:

我在使用自动布局时遇到了一些问题。尤其是在 iOS8 中。

我已经看过网络,在使用UITableViewCell时发现了类似的问题。 但是这里我没有使用UITableViewCell,根本没有UITableView

当它发生时,我只有一个ADBannerView 和一个UIWebView 来处理。

我在 Xcode 调试器中收到以下消息:

Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x14e256f0 'UIView-Encapsulated-Layout-Height' V:[UIView:0x14e6c870(568)]>",
    "<NSLayoutConstraint:0x14d9b320 V:[ADBannerView:0x14d40c30(50)]>",
    "<NSLayoutConstraint:0x14d97b00 V:|-(20)-[ADBannerView:0x14d40c30]   (Names: '|':UIView:0x14e6c870 )>",
    "<NSLayoutConstraint:0x14d34880 ADBannerView:0x14d40c30.bottom == UIView:0x14e6c870.bottom>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x14d34880 ADBannerView:0x14d40c30.bottom == UIView:0x14e6c870.bottom>

作为评论,我想说的第一件事。我不知道第一个约束(UIView-Encapsulated-Layout-Height)来自哪里。 第二件事;我添加了一个约束(尽管已经太多了),以强制执行ADBannerView 的高度,从而解决了显示问题。 但我仍然收到消息(如我所料)。

如果我不添加约束来强制执行ADBannerView 的高度。显示屏的背景变为白色,无论我在哪里点击都会触发 iAd。有点像ADBannerView 的高度填满了整个显示屏。

有解决这个问题的建议吗?

我当然没有忘记:

[adBanner setTranslatesAutoresizingMaskIntoConstraints:NO];

如果有人知道发生了什么,请告诉我。

【问题讨论】:

    标签: ios uitableview uiview autolayout nslayoutconstraint


    【解决方案1】:

    阅读您的约束:

    "<NSLayoutConstraint:0x14d9b320 V:[ADBannerView:0x14d40c30(50)]>"
    

    ADBannerView 的高度为 50 像素

    "<NSLayoutConstraint:0x14d97b00 V:|-(20)-[ADBannerView:0x14d40c30]   (Names: '|':UIView:0x14e6c870 )>"
    

    ADBannerView 被固定在 View 的顶部,边距为 20 像素

    <NSLayoutConstraint:0x14d34880 ADBannerView:0x14d40c30.bottom == UIView:0x14e6c870.bottom>
    

    您已将 ADBannerView 的底部固定到 界面视图。

    "<NSLayoutConstraint:0x14e256f0 'UIView-Encapsulated-Layout-Height' V:[UIView:0x14e6c870(568)]>"
    

    当前视图的高度为 568 像素。

    现在这与您分配给 ADBannerView 的 50 像素的高度相冲突,并且 AdBannerView 被固定在距 UIView 顶部 20 像素的位置。

    要么需要破坏 ADBannerView 的高度,要么需要固定底部,因为这两个约束都不能满足...

    从 UIView 底部取消固定 AdBannerView 以解决此问题

    【讨论】:

    • 我明白了,感谢您的分析。当然,你写的不是我想要的。我最初想修复顶部或底部(不是两者),认为这就足够了。我需要检查我的代码。顺便问一下,我需要自己固定高度吗?或者它是自动的,因为这是一个 ADBannerView?
    • 高度应该是自动的。现在的问题是你想把 AdBannerView 放在哪里?在视图的顶部还是底部?
    猜你喜欢
    • 2021-09-01
    • 2017-02-01
    • 2015-04-09
    • 2015-10-09
    • 2016-03-04
    • 2021-05-21
    • 2014-09-23
    • 2015-01-13
    • 1970-01-01
    相关资源
    最近更新 更多