【发布时间】:2021-03-25 11:08:57
【问题描述】:
我有这个:
extension UIDevice {
static func hasNotch() -> Bool {
let bottom = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.safeAreaInsets.bottom ?? 0
return bottom > 0
}
}
我想申请一个
.edgesIgnoringSafeArea(.top)
只要设备有缺口。
我创建了这个视图修饰符,但出现了各种错误。
struct IgnoreTopSafeArea: ViewModifier {
func body(content: Content) -> some View {
if UIDevice.hasNotch() {
content
.edgesIgnoringSafeArea(.top)
} else {
content
}
}
}
extension View {
func ignoreTopSafeArea() -> some View {
self.modifier(IgnoreTopSafeArea)
}
}
函数声明了一个不透明的返回类型,但它的主体中没有返回语句来推断基础类型
调用“edgesIgnoringSafeArea”的结果未使用
“IgnoreTopSafeArea.Content”(又名“_ViewModifier_Content”)类型的表达式未使用
我该怎么做?
【问题讨论】:
标签: swiftui