這個問題在這里已經有了答案: NavigationLink 在按鈕內不起作用 (1 個回答) 4 小時前關閉。
我是 swift 的新手,我試圖在我的應用程式的每個內容頁面上放置一個“快速退出”按鈕,按鈕本身就是我想要的,但我很難讓實際的導航作業。它會構建,但在單擊時什么也不做。
struct ContentMenu: View {
var body: some View {
ZStack{
VStack {
Spacer()
HStack {
Spacer()
NavigationLink(destination: ContentView2())
{
Button(action:{} ){
Image(systemName: "figure.run.circle.fill")
.resizable(resizingMode: .stretch)
.font(.largeTitle)
.frame(width: 65, height: 65)
.background(Color .red)
.clipShape(Circle())
.foregroundColor(Color .black)}
}.padding()
.shadow(radius: 5)
}
}
}
}
}
uj5u.com熱心網友回復:
在SwiftUI中,NavigationLink本身就是一種特殊型別的按鈕。所以你絕對不需要將按鈕包裝在NavigationLink. 簡單地做:
NavigationLink(destination: ContentView2()) {
Image(systemName: "figure.run.circle.fill")
.resizable(resizingMode: .stretch)
.font(.largeTitle)
.frame(width: 65, height: 65)
.background(Color .red)
.clipShape(Circle())
.foregroundColor(Color .black)}
}.padding()
.shadow(radius: 5)
不要忘記將視圖包裹在 aNavigationStack或 a內NavigationView (如果您計劃支持 iOS 15-),以便導航正常作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/534973.html
標籤:按钮迅捷导航
上一篇:如何將Azure檔案共享的檔案讀取為pandas資料框的csv
下一篇:如何以角度獲取所選按鈕的值
