在手动将子视图和父视图从拖动中撤离时,如何解决导航栏标题重叠的问题?

时间:2019-12-03 17:47:30

标签: swiftui

在SwiftUI中从子视图解散到父视图时,导航栏标题重叠了几毫秒,这是我遇到的问题,这是通过调用函数或拖动以关闭而实现的。

这是用户界面中的错误:

error

这是我要退出的功能的代码

struct AddRecipeView: View {

    //dismiss to parent view method
    @Environment(\.presentationMode) var presentationMode

    //control to verify if user is editing an existing recipe
    @State var editingExistingRecipe = false

    //recipe details
    @EnvironmentObject var recipeDetails: RecipeDetails 

    var body: some View {

        VStack {
            List {
                //code
            }.navigationBarTitle("New Recipe")
        }
        .onAppear {
            //check if user is editing an existing recipe to update details
            if self.editingExistingRecipe == true {

                //update details
                self.updateDetails()

                self.editingExistingRecipe = false
            }
        }
        .edgesIgnoringSafeArea(.bottom)
    }

    func postRecipe(userid: String) {

        self.recipeCategory = self.recipeDetails.recipeCategorySelected
        self.recipeCategoryID = self.recipeDetails.recipeCategorySelectedID

        let Category = self.recipeCategory
        let CategoryID = self.recipeCategoryID

        let details = [
            Category,
            CategoryID
        ]


        for detail in details {
            //check if items are not empty
            print("detail: \(detail)")
            guard !detail.isEmpty else {
                print("empty detail: \(detail)")
                return self.showingAlert = true
            }
        }    

        let db = Firestore.firestore()
        let recipes = db.collection("users/0000/recipes")
        let recipe = recipes.document()

        if self.recipeID.isEmpty {

            recipes.addDocument(data: [
                "category"          : Category,
                "category id"       : CategoryID,
            ]) { err in
               if err != nil {
                    print((err?.localizedDescription)!)
                    return
                }
                print("Success")
            }

            self.recipeDetails.reset()

            DispatchQueue.main.async {
                //dismiss to parent view
                self.presentationMode.wrappedValue.dismiss()
            }
        } else {
            print("doc id = \(self.recipeID)")

            recipes.document(self.recipeID).updateData([
                "category"          : Category,
                "category id"       : CategoryID,
            ]) { err in
               if err != nil {
                    print((err?.localizedDescription)!)
                    return
                }
                print("Success")
            }

            DispatchQueue.main.async {
                //dismiss to parent view
                self.presentationMode.wrappedValue.dismiss()
            }
        }
    }
}

你们知道为什么会这样吗?我是新手,感谢您的帮助。

0 个答案:

没有答案