• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-12 13:18:22 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有一个大约 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 上找不到任何关于“边缘插图”的信息,这是怎么回事?

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



Best Answer-推荐答案


有趣的是,如果初始高度为零,我只会收到此错误,因此这似乎是 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap