gpt4 book ai didi

iOS 10,swift 4.1,将 View 的顶部 anchor 设置为 topLayoutGuide 底部 anchor 导致冲突

转载 作者:行者123 更新时间:2023-11-28 05:52:29 26 4
gpt4 key购买 nike

我试图将我的 View 位置设置在状态栏下方。它适用于 iOS 11+ 中的 safeAreaLayoutGuide,但我正在尝试使用我在网上找到的针对 <11 的建议。

这是我正在尝试的。

if #available(iOS 11.0, *) {
let guide = parentController.view.safeAreaLayoutGuide
NSLayoutConstraint.activate([view.topAnchor.constraintEqualToSystemSpacingBelow(guide.topAnchor, multiplier: 1.0),
view.centerXAnchor.constraint(equalTo: parentController.view.centerXAnchor)])
} else {
NSLayoutConstraint.activate([view.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor),
view.centerXAnchor.constraint(equalTo: parentController.view.centerXAnchor)])
}

在 iOS 10 的情况下,我遇到了这个问题(如下),我不确定这个冲突是从哪里来的。

2018-09-19 13:31:20.097129 iOSTestAppSingleWorkspace[70650:12307124] [LayoutConstraints] 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.
(
"<_UILayoutSupportConstraint:0x60000028d020 _UILayoutSpacer:0x6000001ba4e0'UIVC-topLayoutGuide'.height == 20 (active)>",
"<_UILayoutSupportConstraint:0x60000028ce40 V:|-(0)-[_UILayoutSpacer:0x6000001ba4e0'UIVC-topLayoutGuide'] (active, names: '|':UIView:0x7f92864249c0 )>",
"<NSLayoutConstraint:0x60000028d0c0 V:[_UILayoutSpacer:0x6000001ba4e0'UIVC-topLayoutGuide']-(0)-[UIView:0x7f92864249c0] (active)>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60000028d0c0 V:[_UILayoutSpacer:0x6000001ba4e0'UIVC-topLayoutGuide']-(0)-[UIView:0x7f92864249c0] (active)>

层次结构是一个 UIViewController(parentController) 和一个 subview Controller (此代码运行的地方,引用父 Controller )

subview 是在代码中添加的,可以放置在屏幕上的不同位置,在本例中它位于顶部中心。

最佳答案

您的 subview Controller View 的顶部布局指南将不会引用您的父 View Controller 的顶部布局指南。就像您使用安全区域插图的布局指南所做的那样,如果您引用父 View Controller 的 View 布局指南,您应该没问题。我想冲突的产生是因为您添加了第二个约束,即“我的 View 低于我的顶部布局指南”,默认情况下已经如此

关于iOS 10,swift 4.1,将 View 的顶部 anchor 设置为 topLayoutGuide 底部 anchor 导致冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52413848/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com