問題:
我想accessibilityIdentifier()在 iOS 14 上的 SwiftUI 中使用,但有些代碼支持 iOS 13 。
我可以繼續使用與 iOS 14 版本相同的 API,而在 iOS 13 上不會執行任何操作嗎?
例如:
/// How to make this available on pre-iOS 14 only?
extension View {
func accessibilityIdentifier(_ identifier: String) -> some View {
if #available(iOS 14.0, macOS 11.0, *) {
.accessibilityIdentifier(identifier)
} else {
self
}
}
}
uj5u.com熱心網友回復:
一種可能的方法是創建自己的包裝器,例如(使用 Xcode 13.2 測驗)
extension View {
@ViewBuilder
func accessibility(id identifier: String) -> some View {
if #available(iOS 14.0, macOS 11.0, *) {
self.accessibilityIdentifier(identifier)
} else {
self.accessibility(identifier: identifier)
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/451651.html
上一篇:顫振獲取沒有字串引號的路徑
