我必须检查我的设备是否在 iOS 8+ 中改变了方向。
我的做法是:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
let isLand = UIScreen.main.bounds.width > UIScreen.main.bounds.height
coordinator.animate(alongsideTransition: nil) { _ in
let isLand2 = UIScreen.main.bounds.width > UIScreen.main.bounds.height
print("\(isLand) -> \(isLand2)")
}
}
Run Code Online (Sandbox Code Playgroud)
它在 iPhone 中运行良好,但在 iPad 中isLand已经有了新的值,应该是在定位完成后,所以:
人像 > 风景: true -> true
风景 > 人像: false -> false
根据文档,边界应该随着方向而改变,所以它应该有一个之前/之后的边界,不是吗?
UIScreen 主要边界:
这个矩形是在当前坐标空间中指定的,它考虑了对设备有效的任何界面旋转。因此,当设备在纵向和横向之间旋转时,此属性的值可能会发生变化。
如果我像这样使用当前根视图控制器的边界,它在 iPhone 和 iPad 上都可以正常工作:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过查询从我的 GCP Firestore 集合中获取一组文档,其中文档 ID 位于字符串数组中。我发现其他语言也可以,但我找不到 Golang 的解决方案。
我正在尝试以下操作:
Collection("myCollection").Where(firestore.DocumentID, "in", []string{"id1", "id2", "id3"}).Documents(ctx)
Run Code Online (Sandbox Code Playgroud)
但我有以下错误:
{
"code": 3,
"message": "__key__ filter value must be a Key"
}
Run Code Online (Sandbox Code Playgroud)
我认为将文档 ID 保存为文档本身的字段并不是最佳实践,但它会降低查询的复杂性,并且是一种解决方法。你怎么认为 ?有什么建议吗?