[英]NavigationLink buttons on tvOS with SwiftUI not working
我正在嘗試使用 SwiftUI 在 Apple TV 上構建一個簡單的導航 UI:
據我所知,我需要將NavigationLink
或NavigationLink
與Button
結合使用。
我已經嘗試了幾種實現,但都沒有奏效:
NavigationLink(destination: view2) {
Image("placeholder").frame(width:400, height: 300)
Text("Button")
}
NavigationLink(destination: view2) {
Button(action: {print("hey")}) {
VStack{
Image("placeholder").frame(width:400, height: 300)
Text("Button")
}
}
}
Button(action: {print("hi1")}) {
VStack{
Image("placeholder").frame(width:400, height: 300)
Text("Button")
}
}.background(NavigationLink(destination: view2) { Text("hi2") })
NavigationLink(destination: view2) {
Text("hey")
}.background(Button(action: {print("hey")}) {
VStack{
Image("placeholder").frame(width:400, height: 300)
Text("Button")
}
})
前兩個不能用 Magic Remote 選擇:它們不會變得專注。 當我按下它們時,最后一個根本不會導航到另一個視圖。
如何使用 SwiftUI 在 tvOS 上實現這種導航方式?
NavigationLink
獨立工作,僅在watchOS上(可能會混淆),在所有其他受支持的操作系統中,它應該包含在NavigationView
中才能運行,所以
在偽代碼中
NavigationView {
// ... some code
NavigationLink(...) // must be anywhere inside
// ... other code
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.