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

相关推荐
席子哥哥的代码库17 小时前
自制简单的图片查看器(python)
开发语言·python·swift
打工人你好1 天前
Swift 的 KeyPath 是什么?
swift
struggle20252 天前
Ollmao (OH-luh-毛程序包及源码) 是一款原生 SwiftUI 应用程序,它与 Ollama 集成,可在 Mac 上本地运行强大的 AI 模型
ios·swiftui·swift
神仙别闹4 天前
基于Swift实现拼图游戏
开发语言·搜索引擎·swift
神仙别闹5 天前
基于Swift实现仿IOS闹钟
ios·cocoa·swift
ctf_02269 天前
echarts 3d中国地图飞行线
3d·echarts·swift
没头脑的ht9 天前
UITableView的复用原理
ios·swift
自不量力的A同学11 天前
苹果公司宣布正式开源 Xcode 引擎 Swift Build145
swift
SchneeDuan12 天前
iOS--SDWebImage源码解析
ios·缓存·swift·第三方库·sdwebimage
leluckys13 天前
swift 专题三 swift 规范一
开发语言·ios·swift