0

I am creating an app to give reward stickers for kids. When 10 stickers are collected, I want all stickers are removed from the main view and the image will be shown before removing everything. This image is shown at the 11th click of the button but navigation view to select stickers are also shown on top of this image, which I do not want to be popped up.

Here is my code...

NavigationView {
            ZStack {
                Image("Greenbase")
                    .resizable()
                    .frame(width: self.screenWidth, height: self.screenWidth)
                
                ZStack {
                    
                    ForEach($stickers) { $sticker in
                        VStack {
                            
                            Image(sticker.name)
                                .resizable()
                                .frame(width: self.screenWidth*0.2, height: self.screenWidth*0.2)
                                .offset(x: self.selectedSticker == sticker ? sticker.offset.width + self.dragOffset.width : sticker.offset.width,
                                        y: self.selectedSticker == sticker ? sticker.offset.height + self.dragOffset.height : sticker.offset.height)
                                .gesture(
                                    DragGesture()
                                        .updating(self.$dragOffset, body: { (value, state, transaction) in
                                            if nil == self.selectedSticker {
                                                self.selectedSticker = sticker
                                            }
                                            state = value.translation
                                        })
                                        .onEnded { value in
                                            sticker.offset.height += value.translation.height + dragOffset.height
                                            sticker.offset.width += value.translation.width + dragOffset.width
                                            self.selectedSticker = nil
                                            
                                        }
                                )
                            
                            
                        }//vstack
                        .sheet(isPresented: $isAddingSticker, onDismiss: addSticker) {
                            StampView(sticker: $selectedSticker)
                            
                        }//foreach
                        
                        if counter < 11 {
                            Button {
                                
                                isAddingSticker = true
                                print("button pressed: \(counter)")
                                counter += 1
                                
                                
                            }label: {
                                RoundedRectangle(cornerRadius: 10)
                                    .foregroundColor(Color(red: 55/255, green: 266/255, blue: 213/255))
                                    .frame(width: 300, height: 40, alignment: .center)
                                
                                    .overlay(
                                        Text(" ステッカーをはろう!")
                                            .foregroundColor(Color(red: 41/255, green: 52/255, blue: 98/255))
                                            .font(.title2))
                                
                                
                            }//button label
                            
                        }else {
                            
                            Button{
                                isAddingSticker = false
                                counter = 0
                                removeSticker(at: 1)
                                
                            }label: {
                                Image("WellDone")
                                    .resizable()
                                    .frame(width: self.screenWidth*0.5, height: self.screenWidth*0.5)
                                    .scaleEffect(2.0)
                                    .rotationEffect(Angle(degrees: 360 ))
                                    .animation(.easeInOut(duration: 3.0))
                                
                                
                            }//button label
                        } //else
                    }//Hstack
                    .disabled(isEditing)
                }
            }//zstack stamps
        }//zstac w bc image
    }//body
    
    func removeSticker(at index: Int) {
        self.stickers.removeAll()//< -- Here
    }
    
    func addSticker() {
        
        guard let name = selectedSticker else { return }
        withAnimation {
            stickers.insert(name, at: 0)
        }
        
    }
    
}//struct

I am still super new to Swift... the question should be very basic but hopefully can find the answer.

Yua
  • 7
  • 2

1 Answers1

0

I don't think I understand the question correctly, but you can hide the navigation with this modifier at the end of the navigation view.

NavigationView {
     ...
  }.navigationBarHidden(true)
Yodd
  • 1
  • 1