我有一个大约 300 高的 MKMapView
,它在其他两个 View 之间折叠,就像折叠 View 时通常所做的那样简单地设置高度的动画。
@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 初始设置的问题。他们的解决方案似乎是
何时显示 mapView:
动画到最终位置
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/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |