Reputation: 21
I am creating image button with actions, but however they are not going to their own corresponding view. Can anyone point out of what am I doing wrong or what am I missing in my code below. thank you for the help. here is my code below. I am wrapping it with ZStack, and still no work. what is it missing that I can't see?
struct DashboardView: View {
@State var showingNotifications = false
@State var showingMore = false
@State var showingARCam = false
@State var showingMapView = false
@State var showingProfile = false
var body: some View {
ZStack {
Button(action: {
withAnimation {
self.showingNotifications.toggle()
}
}) {
Image("NotificationButton").offset(x: -120, y: -180)
}.sheet(isPresented: $showingNotifications) {
NotificationView()
.edgesIgnoringSafeArea(.all)
}
Spacer()
Button(action: {
withAnimation {
self.showingMore.toggle()
}
}) {
Image("NotificationButton").offset(x: 80, y: -180)
}.sheet(isPresented: $showingMore) {
MoreView()
.edgesIgnoringSafeArea(.all)
}
Spacer()
Button(action: {
withAnimation {
self.showingARCam.toggle()
}
}) {
Image("AR").offset(x: 10, y: 65)
}.sheet(isPresented: $showingARCam) {
AR()
.edgesIgnoringSafeArea(.all)
}
Spacer()
Button(action: {
withAnimation {
self.showingMapView.toggle()
}
}) {
Image("MapIcon").offset(x: -120, y: 250)
}.sheet(isPresented: $showingMapView) {
MapView()
.edgesIgnoringSafeArea(.all)
}
Button(action: {
withAnimation {
self.showingProfile.toggle()
}
}) {
Image("ProfileIcon").offset(x: 90, y: 250)
}.sheet(isPresented: $showingProfile) {
ProfileView()
.edgesIgnoringSafeArea(.all)
}
}
.background(
Image("Dashboard")
.resizable()
.edgesIgnoringSafeArea(.all)
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
}
}
Upvotes: 2
Views: 525
Reputation: 258393
Remove offsets
... .offset
modifier does not change location of view (and does not affect layout), but only place of drawing, so you see image in one place, but real button is located in different, so tapping image has no effect.
Button(action: {
withAnimation {
self.showingNotifications.toggle()
}
}) {
Image("NotificationButton") // .offset(x: -120, y: -180) // << here !!
}.sheet(isPresented: $showingNotifications) {
Upvotes: 1