gpt4 book ai didi

ios - MKMapView 与零高度约束斗争 - map View 的 edgeInsets?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:54:48 28 4
gpt4 key购买 nike

我有一个大约 300 高的 MKMapView,它在另外两个 View 之间折叠,就像折叠 View 时通常做的那样简单地上下动画高度。

enter image description here

@IBOutlet var heightMap: NSLayoutConstraint!
@IBOutlet var theMap: MKMapView!

当 View 启动时它的高度为零..

override func viewDidLoad() {
super.viewDidLoad()
..
heightMap.constant = 0
}

有一个令人气愤的警告...

[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.
(
"<NSLayoutConstraint:0x6080000904f0 MKMapView:0x7fe6b3000600.height == 0 (active)>",
"<NSLayoutConstraint:0x608000093a60 UILayoutGuide:0x60800018fd80'Edge Insets'.top == MKMapView:0x7fe6b3000600.top + 8 (active)>",
"<NSLayoutConstraint:0x608000093b50 UILayoutGuide:0x60800018fd80'Edge Insets'.bottom == MKMapView:0x7fe6b3000600.bottom (active)>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x608000093b50 UILayoutGuide:0x60800018fd80'Edge Insets'.bottom == MKMapView:0x7fe6b3000600.bottom (active)>

请注意,它似乎在与“edgeInsets”或可能的“Edge Insets”(带空格!)顶部和底部作斗争,

'Edge Insets'.top == MKMapView:0x7fe6b3000600.top + 8
'Edge Insets'.bottom == MKMapView:0x7fe6b3000600.bottom

map View 有一个只读属性.alignmentRectInsets

(实际上,当我打印出来时,无论它是什么,它都是零..

let ari = theMap.alignmentRectInsets
print("wth \(ari)")
> wth UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0)

)

我什至在 MKMapView 上找不到任何关于“边缘插入”的信息,这是怎么回事?

我仔细检查了未安装的约束和常见问题。

最佳答案

有趣的是,如果初始高度为零,我只会收到此错误,因此这似乎是 map View 初始设置的问题。他们的解决方案似乎是

  1. 在 Storyboard 中给 mapView 一个高度(我做了 100 个)
  2. 制作通过在界面生成器中选中隐藏框来隐藏 mapView

何时显示 mapView:

  1. 取消隐藏
  2. 最小化它(我将常量设置为 .ulpOfOne 而不是零,因为从技术上讲,帧不应该退化。)
  3. 动画到最终位置

    class ViewController: UIViewController{
    @IBOutlet weak var m: MKMapView!
    @IBOutlet weak var h: NSLayoutConstraint!
    @IBAction func t(_ sender: Any) {
    m.isHidden = false
    h.constant = .ulpOfOne
    view.layoutIfNeeded()
    h.constant = 100
    UIView.animate(withDuration: 3) {
    self.view.layoutIfNeeded()
    }
    }
    }

仅供引用,我实际上会为此使用 UIStackView,而只是为 isHidden 设置动画,然后您甚至不必处理代码中的约束。

关于ios - MKMapView 与零高度约束斗争 - map View 的 edgeInsets?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43322973/

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