• <bdo id='4Smu2'></bdo><ul id='4Smu2'></ul>

      <legend id='4Smu2'><style id='4Smu2'><dir id='4Smu2'><q id='4Smu2'></q></dir></style></legend>

      <small id='4Smu2'></small><noframes id='4Smu2'>

        <i id='4Smu2'><tr id='4Smu2'><dt id='4Smu2'><q id='4Smu2'><span id='4Smu2'><b id='4Smu2'><form id='4Smu2'><ins id='4Smu2'></ins><ul id='4Smu2'></ul><sub id='4Smu2'></sub></form><legend id='4Smu2'></legend><bdo id='4Smu2'><pre id='4Smu2'><center id='4Smu2'></center></pre></bdo></b><th id='4Smu2'></th></span></q></dt></tr></i><div id='4Smu2'><tfoot id='4Smu2'></tfoot><dl id='4Smu2'><fieldset id='4Smu2'></fieldset></dl></div>

        <tfoot id='4Smu2'></tfoot>

        自定义弹出窗口显示时的 SwiftUI 导航栏外观和功能

        时间:2024-04-14
          <tbody id='QLZcn'></tbody>
        • <bdo id='QLZcn'></bdo><ul id='QLZcn'></ul>
          <legend id='QLZcn'><style id='QLZcn'><dir id='QLZcn'><q id='QLZcn'></q></dir></style></legend>
        • <small id='QLZcn'></small><noframes id='QLZcn'>

            <tfoot id='QLZcn'></tfoot>

          • <i id='QLZcn'><tr id='QLZcn'><dt id='QLZcn'><q id='QLZcn'><span id='QLZcn'><b id='QLZcn'><form id='QLZcn'><ins id='QLZcn'></ins><ul id='QLZcn'></ul><sub id='QLZcn'></sub></form><legend id='QLZcn'></legend><bdo id='QLZcn'><pre id='QLZcn'><center id='QLZcn'></center></pre></bdo></b><th id='QLZcn'></th></span></q></dt></tr></i><div id='QLZcn'><tfoot id='QLZcn'></tfoot><dl id='QLZcn'><fieldset id='QLZcn'></fieldset></dl></div>

                  本文介绍了自定义弹出窗口显示时的 SwiftUI 导航栏外观和功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试显示一个自定义弹出窗口,当它显示时,我需要禁用背景并将其变暗,就像在内置警报功能中所做的那样.但是,当视图中有导航栏时,彩色图层不能放在导航栏上方.

                  I am trying to show a custom popup, and while that is showing, I'd need to disable and darken the background just as it is done in the built-in alert functionality. However, when there is a navigation bar in the view, the coloured layer can't be put on top of the navigation bar.

                  所需的结果就像在内置警报修改器中所做的那样,使整个背景变暗(使用导航栏),同时禁用与背景(和导航栏)交互的能力.

                  The desired outcome would be just as it is done in the built-in Alert modifier, to darken the whole background (with navbar), while disabling the ability to interact with the background (and the navbar).

                  有没有办法实现与内置警报修饰符相同的功能和外观?

                  Is there a way to achieve the same functionality and appearance as in with the built-in Alert modifier?

                  示例项目代码

                  import SwiftUI
                  
                  struct ContentView: View {
                      @State private var isShowingPopup = false
                      
                      var body: some View {
                          NavigationView {
                              VStack {
                                  Text("Just a random text")
                                      .padding(.bottom, 100)
                                  Button("Show popup") {
                                      isShowingPopup = true
                                  }
                              }
                              .showPopup(isActive: isShowingPopup, action: { isShowingPopup = false })
                              .navigationBarTitle("Test navbar", displayMode: .inline)
                              .navigationBarItems(
                                  trailing: Button(
                                      action: { print("profile tapped")},
                                      label: {
                                          Text("Profile")
                                      }
                                  )
                              )
                          }
                      }
                  }
                  
                  extension View {
                      func showPopup(
                          isActive: Bool,
                          action: @escaping () -> Void
                      ) -> some View {
                          ZStack {
                              self
                              if isActive {
                                  Color.black
                                      .frame(maxWidth: .infinity, maxHeight: .infinity)
                                      .edgesIgnoringSafeArea(.all)
                                      .opacity(0.51)
                                      .zIndex(1)
                                  Popup(action: action)
                                      .zIndex(2)
                              }
                          }
                      }
                  }
                  
                  struct Popup: View {
                      let action: () -> Void
                      
                      var body: some View {
                          VStack {
                              Text("This is a popup")
                                  .foregroundColor(.black)
                                  .padding()
                              Button("OK", action: action)
                                  .foregroundColor(.blue)
                          }
                          .background(Color.white)
                          .cornerRadius(8)
                      }
                  }
                  

                  感谢您的帮助!

                  推荐答案

                  最后添加.在 NavigationView 的最后添加 showPopup

                  Add in the last. Add showPopup in the last of the NavigationView

                  NavigationView {
                      VStack {
                          Text("Just a random text")
                              .padding(.bottom, 100)
                          Button("Show popup") {
                              isShowingPopup = true
                          }
                      }
                      
                      .navigationBarTitle("Test navbar", displayMode: .inline)
                      .navigationBarItems(
                          trailing: Button(
                              action: { print("profile tapped")},
                              label: {
                                  Text("Profile")
                              }
                          )
                      )
                  }
                  .showPopup(isActive: isShowingPopup, action: { isShowingPopup = false }) //<---Here
                  
                  

                  这篇关于自定义弹出窗口显示时的 SwiftUI 导航栏外观和功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:错误:从 JSON 文件发送到 NSMutableArray 的不可变对象的变异方法 下一篇:在弹出窗口中显示地图 v2 不在 android 中显示?

                  相关文章

                      <bdo id='DAB8t'></bdo><ul id='DAB8t'></ul>
                    1. <i id='DAB8t'><tr id='DAB8t'><dt id='DAB8t'><q id='DAB8t'><span id='DAB8t'><b id='DAB8t'><form id='DAB8t'><ins id='DAB8t'></ins><ul id='DAB8t'></ul><sub id='DAB8t'></sub></form><legend id='DAB8t'></legend><bdo id='DAB8t'><pre id='DAB8t'><center id='DAB8t'></center></pre></bdo></b><th id='DAB8t'></th></span></q></dt></tr></i><div id='DAB8t'><tfoot id='DAB8t'></tfoot><dl id='DAB8t'><fieldset id='DAB8t'></fieldset></dl></div>

                      <small id='DAB8t'></small><noframes id='DAB8t'>

                      <tfoot id='DAB8t'></tfoot>

                      <legend id='DAB8t'><style id='DAB8t'><dir id='DAB8t'><q id='DAB8t'></q></dir></style></legend>