【发布时间】:2021-08-29 23:18:04
【问题描述】:
我在这里声明了这个子视图:
import SwiftUI
struct NavigationBarView: View {
@State private var showingMenu = false
var body: some View {
HStack {
Button(action: {print("test")}, label: {
Image(systemName: "line.horizontal.3")
.font(.title)
.foregroundColor(.white)
})
Spacer()
Text("SAT Daily")
.font(.custom("Nunito-Bold", size: 30))
.foregroundColor(.white)
.onTapGesture {
print("test")
}
Spacer()
Button(action: {print("test1")}, label: {
Image(systemName: "person.circle")
.font(.title)
.foregroundColor(.white)
})
}.onTapGesture {
print("bruh")
}
}
}
我在我的主页中调用这个视图来显示它(上面的视图是一个标题):
var body: some View {
NavigationView {
ZStack {
Color(UIColor(red: 0.067, green: 0.137, blue: 0.322, alpha: 1))
.ignoresSafeArea()
VStack() {
NavigationBarView()
.padding(.horizontal, 15)
.padding(.bottom)
.padding(.top, UIApplication.shared.windows.first?.safeAreaInsets.top)
.background(Color(UIColor(red: 0.024, green: 0.092, blue: 0.267, alpha: 1).cgColor))
.zIndex(1)
ScrollView(/*@START_MENU_TOKEN@*/.vertical/*@END_MENU_TOKEN@*/, showsIndicators: false, content: {
如果我单击任何打印相应语句的按钮,则不会打印。我该如何解决这个问题?
个人资料图标和菜单图标是不起作用的按钮。标题(带有 SAT Daily 徽标)是在我的主页上调用的子视图。
【问题讨论】:
-
它对我有用。您能否显示您主页的完整代码(包括您放置
navigationBarHidden的位置)?顺便说一句,不错的应用程序 -
我运行了它,按钮可以点击...
-
是的,很多人似乎都在说它的工作原理,这让我更加困惑。可能是我在手机上测试。我会在模拟器上测试一下看看。
标签: ios swift mobile swiftui swift3