Swift 安全区域布局指南和可视化格式语言

2023-09-10移动开发问题
2

本文介绍了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 安全区域布局指南和可视化格式语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法将文件从捆绑包复制到 iOS 中的文档目录
Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)...
2024-04-15 移动开发问题
4

如何复制“字典"在斯威夫特?
How to copy a quot;Dictionaryquot; in Swift?(如何复制“字典在斯威夫特?)...
2024-04-15 移动开发问题
10

Swift - 迭代结构对象时如何对其进行变异
Swift - How to mutate a struct object when iterating over it(Swift - 迭代结构对象时如何对其进行变异)...
2024-04-15 移动开发问题
7

如何使用 Swift 将文本复制到剪贴板/粘贴板
How to copy text to clipboard/pasteboard with Swift(如何使用 Swift 将文本复制到剪贴板/粘贴板)...
2024-04-15 移动开发问题
9

Swift 无法使用类型为“([Score],Score)"的参数列表调用“find",其中 Sco
Swift Cannot invoke #39;find#39; with an argument list of type #39;([Score], Score)#39; where Score is a struct(Swift 无法使用类型为“([Score],Score)的参数列表调用“find,其中 Score 是一个结构)...
2024-04-15 移动开发问题
6

如何使用 UIImageViewExtension 与 Swift 异步加载图像并防止重复图像或错误图像加载到单元格
How to load image asynchronously with Swift using UIImageViewExtension and preventing duplicate images or wrong Images loaded to cells(如何使用 UIImageViewExtension 与 Swift 异步加载图像并防止重复图像或错误图像加载到单元格) - IT屋-程序员软...
2024-04-15 移动开发问题
3