xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

free version GitHub Copilot All In One

free version GitHub Copilot All In One

AI 编程编码助手

GitHub Copilot free

image

Responses are limited to 2,000 code completions and 50 chat messages per month.

https://github.com/settings/copilot

GitHub Copilot Pro

image

https://github.com/github-copilot/signup/copilot_individual

demos

VS Code

import SwiftUI


struct FullScreenModalView: View {
  @Environment(\.presentationMode) var presentationMode
  var body: some View {
    VStack {
      Text("Hello, World!")
        .padding()
      Button("Dismiss") {
        presentationMode.wrappedValue.dismiss()
      }
    }
    .frame(maxWidth: .infinity, maxHeight: .infinity)
    .background(Color.red)
    .edgesIgnoringSafeArea(.all)
    .onTapGesture {
      presentationMode.wrappedValue.dismiss()
    }
  }
}



struct ContentView: View {
  @State private var isPresented = false
  var body: some View {
    Button("Show Full Screen Modal") {
      self.isPresented.toggle()
      // isPresented.toggle()
    }
    .fullScreenCover(isPresented: $isPresented, content: FullScreenModalView.init)
  }
}

struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
    ContentView()
  }
}

@main
struct MyApp: App {
  var body: some Scene {
    WindowGroup {
      ContentView()
    }
  }
}

image

The provided code defines a SwiftUI view named FullScreenModalView. This view is designed to be displayed as a full-screen modal. It uses the @Environment property wrapper to access the presentationMode environment value, which allows the view to dismiss itself.

The body property of the FullScreenModalView struct contains the view's layout. It consists of a vertical stack (VStack) that includes a Text view displaying "Hello, World!" and a Button labeled "Dismiss". When the button is pressed, it triggers the dismissal of the modal by calling presentationMode.wrappedValue.dismiss().

The VStack is configured to take up the maximum available width and height using the .frame(maxWidth: .infinity, maxHeight: .infinity) modifier. The background color of the view is set to red with the .background(Color.red) modifier. The .edgesIgnoringSafeArea(.all) modifier ensures that the view extends to cover the entire screen, including areas like the status bar.

Additionally, the view includes a tap gesture recognizer with the .onTapGesture modifier. This gesture recognizer also calls presentationMode.wrappedValue.dismiss() when the view is tapped, providing an alternative way to dismiss the modal.

Overall, this code creates a full-screen modal view with a red background that can be dismissed either by tapping the "Dismiss" button or by tapping anywhere on the screen.

image

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs

https://www.youtube.com/watch?v=SdIWZzl9h-w



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2024-12-28 23:30  xgqfrms  阅读(5)  评论(1编辑  收藏  举报