Swift 安全区域布局指南和可视化格式语言 [英] Swift Safe Area Layout Guide and Visual Format Language

查看:27
本文介绍了Swift 安全区域布局指南和可视化格式语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Apple 的视觉格式语言将视图限制为新的 SafeiOS 11 中的区域布局指南.但是,我得到一个例外:

I want to use Apples visual format language to constrain a view to the new Safe Area Layout Guide in iOS 11. However, I get an exception:

-[NSLayoutYAxisAnchor nsli_superitem]:无法识别的选择器发送到实例 0x1c447ed40

-[NSLayoutYAxisAnchor nsli_superitem]: unrecognized selector sent to instance 0x1c447ed40

    //Make View Dictionary
    var views: [String: Any] = ["left": self.leftContainer]

    //Check swift version and add appropriate piece to the view dictionary
    if #available(iOS 11, *) {
        views["topGuide"] = self.view.safeAreaLayoutGuide.topAnchor
    }else{
        views["topGuide"] = self.topLayoutGuide
    }

    //Make the constraint using visual format language
    let leftVertical = NSLayoutConstraint.constraints(withVisualFormat: "V:[topGuide][left]|", options: [], metrics: nil, views: views)

    //Add the new constraint
    self.view.addConstraints(vertical)

我喜欢可视化格式语言的原因是因为在某些情况下你可以用更少的代码添加很多约束.

The reason I like visual format language is because you a can add lot of constraints with less code in some cases.

有什么想法吗?

推荐答案

我想使用 Apple 的视觉格式语言将视图约束到新的安全区域布局指南

I want to use Apples visual format language to constrain a view to the new Safe Area Layout Guide

你不能.无法通过视觉格式语言访问安全区域布局指南.我已经提交了一个错误,我建议你也这样做.

You can't. There is no access to the safe area layout guide through the visual format language. I've filed a bug on this, and I suggest you do the same.

这篇关于Swift 安全区域布局指南和可视化格式语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆