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 安全区域布局指南和可视化格式语言


- URL编码Swift iOS 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- UITextView 内容插图 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01