Swift Safe Area Layout Guide and Visual Format Language(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 安全区域布局指南和可视化格式语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Swift 安全区域布局指南和可视化格式语言


基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01