SwiftUI Swift 多个 sheet

今天做一个多个 sheet 的效果,点击下面三个按钮打开不同的 sheet


Show me the code

swift 复制代码
import SwiftUI

enum CurrentActiveSheet: Identifiable {
    case add, edit, delete

    var id: Int {
        hashValue
    }
}

struct MoreSheet: View {
    @State var currentActiveSheet: CurrentActiveSheet?

    var body: some View {
        HStack(spacing: 20) {
            Text("add")
                .padding()
                .background(Color.red)
                .onTapGesture {
                    currentActiveSheet = .add
                }
            
            Text("edit")
                .padding()
                .background(Color.green)
                .onTapGesture {
                    currentActiveSheet = .edit
                }
            
            Text("delete")
                .padding()
                .background(Color.blue)
                .onTapGesture {
                    currentActiveSheet = .delete
                }
        }
        .foregroundColor(Color.white)
        .sheet(item: $currentActiveSheet) { item in
            switch item {
            case .add:
                Text("add")
            case .edit:
                Text("edit")
            case .delete:
                Text("delete")
            }
        }
    }
}

struct MoreSheet_Previews: PreviewProvider {
    static var previews: some View {
        MoreSheet()
    }
}

Preview


喜欢或对你有帮助,点个赞吧,自己先点个嘿嘿。
有错误或者疑问还请评论指出。
我的个人网站 点击访问 hongweizhu.com

END

相关推荐
非专业程序员21 小时前
iOS/Swift:深入理解iOS CoreText API
ios·swift
xingxing_F1 天前
Swift Publisher for Mac 版面设计和编辑工具
开发语言·macos·swift
YGGP2 天前
【Swift】LeetCode 438. 找到字符串中所有字母异位词
swift
QWQ___qwq2 天前
Swift中.gesture的用法
服务器·microsoft·swift
QWQ___qwq3 天前
SwiftUI 布局之美:Padding 让界面呼吸感拉满
ios·swiftui·swift
用户093 天前
SwiftUI 键盘快捷键作用域深度解析
ios·面试·swiftui
用户093 天前
Xcode 26 的10个新特性解析
ios·面试·swift
白熊1884 天前
【图像大模型】ms-swift 深度解析:一站式多模态大模型微调与部署框架的全流程使用指南
开发语言·ios·swift
用户34747547833284 天前
把SwiftUI View 转为图片
ios·swiftui
YGGP4 天前
【Swift】LeetCode 1. 两数之和
swift