首页 > 其他分享 >swiftui之页面跳转数据连接

swiftui之页面跳转数据连接

时间:2024-11-02 15:18:33浏览次数:6  
标签:struct show Text title swiftui 跳转 var View 页面

import SwiftUI

struct DesignCode: View {
    @State var show = false
    @State var viewState = CGSize.zero
    
    var body: some View {
        ZStack {
            TitleView()
                .blur(radius: show ? 20 : 0)
            
            
            CardBottomView()
                .blur(radius: show ? 20 : 0)
                .animation(.default)
            
            CardView()
                .background(show ? Color.red : Color.blue)
                .cornerRadius(10)
                .shadow(radius: 20 )
                .offset(x: 0, y: show ? -400 : -40)
                .scaleEffect(0.85)
                .rotationEffect(Angle(degrees: show ? 15.0 : 0))
                //.rotation3DEffect(Angle(degrees: show ? 50 : 0), axis: (x: 10.0, y: 10.0, z: 10.0))
                .blendMode(.hardLight)
                .animation(.easeInOut(duration: 0.7))
                .offset(x: viewState.width, y: viewState.height)
            
            CardView()            
                .background(show ? Color.red : Color.yellow)
                .cornerRadius(10)
                .shadow(radius: 20 )
                .offset(x: 0, y: show ? -200 : -20)
                .scaleEffect(0.9)
                .rotationEffect(Angle(degrees: show ? 10.0 : 0))
                //.rotation3DEffect(Angle(degrees: show ? 40 : 0), axis: (x: 10.0, y: 10.0, z: 10.0))
                .blendMode(.hardLight)
                .animation(.easeInOut(duration: 0.5))
                .offset(x: viewState.width, y: viewState.height)
            
            CertificateView()
                .offset(x: viewState.width, y: viewState.height)
                .scaleEffect(0.95)
                .rotationEffect(Angle(degrees: show ? 5.0 : 0))
                //.rotation3DEffect(Angle(degrees: show ? 30 : 0), axis: (x: 10.0, y: 10.0, z: 10.0))
                .animation(.spring())
                .onTapGesture {
                    self.show.toggle()
                }
                .gesture(
                    DragGesture()
                        .onChanged { value in
                            self.viewState = value.translation
                            self.show = true
                        }
                        .onEnded { value in
                            self.viewState = CGSize.zero
                            self.show = false
                            
                        }
                )
        }
    }
}

struct DesignCode_Previews: PreviewProvider {
    static var previews: some View {
        DesignCode()
    }
}

struct CardView: View {
    var body: some View {
        VStack {
            Text("hhdshfs")
        }
        .frame(width: 340.0, height: 300.0)
        
        .offset(x: 0, y: -20)
    }
}

struct CertificateView: View {
    var body: some View {
        VStack {
            HStack {
                VStack(alignment:.leading) {
                    Text("UI Design")
                        .font(.largeTitle)
                    Text("Certificate")
                    
                }
                Spacer()
                Image("c4")
                    .resizable()
                    .frame(width: 30, height: 30)
            }
            .padding(.horizontal)
            Spacer()
            Image("1-1")
        }
        .frame(width: 340.0, height: 300.0)
        .background(Color.blue)
        .cornerRadius(10)
        .shadow(radius: 20)
    }
}

struct TitleView: View {
    var body: some View {
        VStack {
            HStack {
                Text("Certificates")
                    .font(.largeTitle)
                Spacer()
            }
            Image("c1-1")
                .resizable()
                .frame(width: 100, height:100)
            Spacer()
        }
        .padding()
    }
}

struct CardBottomView: View {
    var body: some View {
        VStack(spacing:20) {
            Rectangle()
                .frame(width: 60, height: 6)
                .cornerRadius(3.0)
                .opacity(0.2)
            
            Text("fgdshghsfdskguydiassf asiuy usaotufsdiua asfusiuga  euituaosgfu ias fusiu fgaisugia  uasdiguaisg UFDIugfoa  effet")
                .lineLimit(10)
            Spacer()
        }
        .frame(minWidth: 0, maxWidth: .infinity)
        .padding()
        .padding(.horizontal)
        .background(Color.white)
        .cornerRadius(30)
        .shadow(radius: 20)
        .offset(y: 600)
    }
}
import SwiftUI

struct Home: View {
    //var menuItems = ["My Account",  "Billing",  "Team", "Sign out"]
    
    @State var show = false
    @State var showProfile = false
    
    var body: some View {
        ZStack {
            HomeList()
                .blur(radius: show ? 20 : 0)
                .scaleEffect(showProfile ? 0.95 : 1)
                .animation(.default)
            
            DesignCode()
                .background(Color.white)
                .cornerRadius(30)
                .shadow(radius: 20)
                .animation(.interactiveSpring())
                .offset(y: showProfile ? 45 : UIScreen.main.bounds.height)
            
            MenuButton(show: $show)
                .offset(x: -30, y: showProfile ? 0 : 80)
                .animation(.spring())
            
            MenuRight(show: $showProfile)
                .offset(x: -16, y: showProfile ? 0 : 88)
                .animation(.spring())
            
            MenuView(show: $show)
        }
    }
}

struct Home_Previews: PreviewProvider {
    static var previews: some View {
        Home()
    }
}

struct MenuRow: View {
    var image = "creditcard"
    var text = "My Account"
    
    var body: some View {
        HStack {
            Image(systemName: image)
                .imageScale(.large)
                .foregroundColor(.blue)
                .frame(width:32,height: 32)
            Text(text)
                .font(.headline)
            Spacer()
        }
    }
}


struct Menu : Identifiable {
    var id = UUID()
    var title : String
    var icon : String
}

let menuData = [
    Menu(title: "My Account", icon: "person.crop.circle"),
    Menu(title: "Billing", icon: "creditcard"),
    Menu(title: "Team", icon: "person.and.person"),
    Menu(title:  "Sign out", icon: "arrow.uturn.down")
]

struct MenuView: View {
    var menu = menuData
    @Binding var show: Bool
    
    var body: some View {
        VStack(alignment: .leading, spacing: 20) {
            
            ForEach(menu) { item in
                MenuRow(image: item.icon, text: item.title)
            }
            Spacer()
        }
        .padding(.top, 20)
        .padding(30)
        .frame(minWidth: 0, maxWidth: .infinity)
        .background(Color.white)
        .cornerRadius(30)
        .padding(.trailing, 60)
        .shadow(radius: 20 )
        .rotation3DEffect(Angle(degrees: show ? 0 : 60), axis: (x: 0, y: 10.0, z: 0))
        .animation(.default)
        .offset(x: show ? 0 : -UIScreen.main.bounds.width)
        .onTapGesture {
            self.show.toggle()
        }
    }
}

struct CircleButton: View {
    var icon = "person.crop.circle"
    
    var body: some View {
        HStack {
            Image(systemName: icon)
                .foregroundColor(.black)
        }
        .frame(width: 44, height: 44)
        .background(Color.white)
        .cornerRadius(30)
        .shadow(color: .black, radius: 10, x: 0.0, y: 10)
    }
}

struct MenuButton: View {
    @Binding var show: Bool
    
    var body: some View {
        ZStack {
            Button(action: { self.show.toggle()}) {
                HStack {
                    Spacer()
                    Image(systemName: "list.dash")
                        .foregroundColor(.black)
                }
                .padding(.trailing, 20)
                .frame(width: 90, height: 60)
                .background(Color.white)
                .cornerRadius(30)
                .shadow(color: .black, radius: 10, x: 0.0, y: 10)
            }
            Spacer()
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity,alignment: .topLeading)
    }
}

struct MenuRight: View {
    @Binding var show: Bool
    
    var body: some View {
        ZStack {
            HStack {
                Button(action: { self.show.toggle()}) {
                    CircleButton(icon: "person.crop.circle")
                }
                
                Button(action: { self.show.toggle()}) {
                    CircleButton(icon: "bell")
                }
                
            }
            Spacer()
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity,alignment: .topTrailing)
    }
}
import SwiftUI

struct UpdateList: View {
    var updates = updateData
    @ObservedObject var store = UpdateStore(updates: updateData)
    
    func addUpdate() {
        store.updates.append(Update(image: "c1", title: "New title", text: "djsf", date: "22"))
    }
    
    func move(from source: IndexSet, to destination: Int) {
        store.updates.move(fromOffsets: source, toOffset: destination)
    }
    
    
    var body: some View {
        NavigationView {
            VStack {
                
                List {
                    ForEach(store.updates) { item in
                        NavigationLink(destination: UpdateDetail(title:item.title, text: item.text, image: item.image)) {
                            HStack(spacing: 12) {
                                Image(item.image)
                                    .resizable()
                                    .aspectRatio(contentMode: .fit)
                                    .frame(width: 80, height: 80)
                                    .cornerRadius(20)
                                
                                VStack(alignment: .leading) {
                                    Text(item.title)
                                        .font(.headline)
                                    Text(item.text)
                                        .lineLimit(2)
                                        .lineSpacing(4)
                                        .font(.subheadline)
                                        .frame(height: 50)
                                    Text(item.date)
                                        .font(.caption)
                                        .fontWeight(.bold)
                                        .foregroundColor(.gray)
                                }
                            }
                            .padding(30)
                        }
                    }
                    .onDelete { index in
                        self.store.updates.remove(at: index.first!)
                    }
                    .onMove(perform: move)
                    
                }
                .navigationTitle(Text("Updates"))
                .navigationBarItems(
                    leading: Button(action: addUpdate, label: {
                        Image(systemName: "plus")
                    })
                    ,trailing:
                        EditButton()
                )
                
            }
        }
    }
}

struct UpdateList_Previews: PreviewProvider {
    static var previews: some View {
        UpdateList()
    }
}

struct Update: Identifiable {
    var id = UUID()
    var image: String
    var title: String
    var text: String
    var date: String
}

let updateData = [
    Update(image: "c1", title: "Swift UI", text: "learn how to build", date: "JUN 26"),
    Update(image: "c1", title: "Frs d g g d h g d", text: "ggh gdgthd", date: "JUN 11"),
    Update(image: "c1", title: "fhgdfk fdgs dgg f", text: "gfs fs gfa", date: "JUN 2"),
    Update(image: "c1", title: "hgh dfgsa a f gf d", text: "leg  gfs f dd gg", date: "JUN 6")
]
import SwiftUI

struct Settings: View {
    @State var receive = false
    @State var number = 11
    @State var selection = 2
    @State var date = Date()
    @State var email = ""
    @State var submit = false
    
    var body: some View {
        NavigationView {
            Form {
                Toggle(isOn: $receive) {
                    Text("hh")
                }
                
                Stepper(value: $number, in: 1...12) {
                    Text("\(number)  kk\(number > 1 ? "s" : "")")
                }
                
                Picker(selection: $selection, label: Text("This is a Picker")) {
                    Text("Picker1").tag(1)
                    Text("Picker2").tag(2)
                }
                
                DatePicker(selection: $date, label: { Text("This is a Date") })
                
                
                Section(header: Text("Email")) {
                    TextField("Placeholder", text: $email)
                        .textFieldStyle(RoundedBorderTextFieldStyle())
                }
                
                Button(action: {self.submit.toggle()}, label: {
                    Text("Submit")
                })
                .alert(isPresented: $submit, content: {
                    Alert(title: Text("Thanks"), message: Text("Email:\(email)"))
                })
            }
            .navigationBarTitle("Settings")
        }
    }
}

struct Settings_Previews: PreviewProvider {
    static var previews: some View {
        Settings()
    }
}
import SwiftUI

struct TabBar: View {
    var body: some View {
        TabView (selection: .constant(1)){
            Home()
                .tabItem ({
                    Image(systemName: "photo")
                    Text("Home")
                })
                .tag(1)
            
            DesignCode()
                .tabItem ({
                    Image(systemName: "photo")
                    Text("Certificates")
                })
                .tag(2)
            
            Settings()
                .tabItem ({
                    Image(systemName: "photo")
                    Text("Settings")
                })
                .tag(3)
        }
    }
}

struct TabBar_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            TabBar()
            TabBar()
                .environment(\.colorScheme, .dark)
                .environment(\.sizeCategory, .extraExtraLarge)
        }
    }
}
import SwiftUI
import Combine

class UpdateStore: ObservableObject {
    var didChange = PassthroughSubject<Void, Never>()
    
   @Published var updates: [Update] {
        didSet {
            didChange.send()
        }
    }
    init(updates: [Update] = []) {
        self.updates = updates
    }
}
import SwiftUI

struct UpdateDetail: View {
    var title = "sdfg"
    var text = "fdgf"
    var image = "c1"
    
    var body: some View {
        VStack {
            Text(title)
                .font(.largeTitle)
                .fontWeight(.heavy)
            Image(image)
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: 200, height: 200)
            Text(text)
                .lineLimit(nil)
                .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
            Spacer()
        }
        .padding(30)
    }
}

struct UpdateDetail_Previews: PreviewProvider {
    static var previews: some View {
        UpdateDetail()
    }
}

 

import SwiftUI

struct HomeList: View {
    var courses = coursesData
    
    var body: some View {
        NavigationView {
            VStack {
                HStack {
                    
                    VStack(alignment: .leading) {
                        Text("Courses")
                            .font(.largeTitle)
                            .fontWeight(.heavy)
                        Text("22 coursess")
                            .foregroundColor(.gray)
                    }
                    Spacer()
                }
                .padding(.leading, 70)
                .padding(.bottom, 40)
                
                ScrollView(.horizontal, showsIndicators: false) {
                    HStack(spacing:30) {
                        ForEach(courses) { item in
                            NavigationLink(
                                destination: DesignCode()) {
                                
                                GeometryReader { geometry in
                                    CourseView(
                                        title: item.title,
                                        image: item.image,
                                        color: item.color,
                                        shadowColor: item.shadowColor)
                                        .rotation3DEffect(Angle(degrees: Double(geometry.frame(in: .global).minX - 40) / -20), axis: (x:0, y: 10.0, z: 0))
                                }
                                .frame(width: 246, height: 150)
                            }
                        }
                    }
                    .padding(.leading, 40)
                    Spacer()
                }
            }
            .padding(.top, 0)
        }
    }
}

struct HomeList_Previews: PreviewProvider {
    static var previews: some View {
        HomeList()
    }
}

struct CourseView: View {
    var title = "Bulid an app wjsfs g dsfsgfgh "
    var image = "c1"
    var color = Color("backgroundShadow")
    var shadowColor =  Color("backgroundShadow")
    
    var body: some View {
        VStack(alignment: .leading) {
            Text(title)
                .font(.title)
                .fontWeight(.bold)
                .foregroundColor(.white)
                .padding(30)
                .lineLimit(4)
                .padding(.trailing, 50)
            Spacer()
            Image(image)
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: 246, height: 200)
                .padding(.bottom, 30)
                
        }
        .background(color)
        .cornerRadius(30)
        .frame(width: 245, height: 360)
        .shadow(color: shadowColor, radius: 20, x: 0, y: 20)
    }
}


struct Course: Identifiable {
    var id = UUID()
    var title: String
    var image: String
    var color: Color
    var shadowColor: Color
}

let coursesData = [
    Course(
        title: "Build an app with SwiftUI",
        image: "c1",
        color: Color("backgroundShadow"),
        shadowColor: Color("backgroundShadow")),
    Course(
        title: "Build dsfhds fgsg dfs",
        image: "c1",
        color: Color.red,
        shadowColor: Color.red),
    Course(
        title: "Blue an app with blue",
        image: "c1",
        color: Color.blue,
        shadowColor: Color.blue),
]

import Foundation

class ToDo: ObservableObject {
    @Published var ToDoList: [SingleToDo]
    var count = 0
    
    init() {
        self.ToDoList = []
    }
    
    init(data: [SingleToDo]) {
        self.ToDoList = []
        for item in data {
            self.ToDoList.append(SingleToDo(title: item.title, duedate: item.duedate, id: self.count))
            count += 1
        }
    }
    
    func check(id: Int) {
        self.ToDoList[id].isChecked.toggle()
    }
}

struct SingleToDo: Identifiable {
    var title: String = ""
    var duedate: Date = Date()
    var isChecked: Bool = false
    var id: Int = 0
}

标签:struct,show,Text,title,swiftui,跳转,var,View,页面
From: https://blog.csdn.net/qq_63007445/article/details/143450952

相关文章

  • 无法显示页面,因为发生内部程序错误
    问题原因:web.config 文件在Windows操作系统云虚拟主机的子目录或二级目录下存在时,可能会导致内部程序错误,因为云虚拟主机不支持这些目录中的 web.config 文件。解决步骤:重命名 web.config 文件:进入子目录或二级目录。将 web.config 文件重命名为其他名称,例......
  • python在word的页脚插入页面
    1、插入简易页码importwin32com.clientaswin32fromwin32com.clientimportconstantsimportosdoc_app=win32.gencache.EnsureDispatch('Word.Application')#打开word应用程序doc_app.Visible=Truedoc=doc_app.Documents.Add()footer=doc.Sections(1).Foo......
  • 3.2 页面异常-1
    系列文章目录文章目录系列文章目录3.2页面异常MmAccessFault()MmNotPresentFault()MmNotPresentFaultVirtualMemory()MmGetPageOp()MmReadFromSwapPage()3.2页面异常前面曾经提到,在为交割而分配一个区间时,区块的类型变成了MEM_COMMIT,此后这个区间就可以被访问了......
  • webpack5配置传统jQuery多页面应用
    简介大家好,我是chenms,最近我们公司有要求需要开发几个以前传统的前后端不分离的jQuery老项目,现在大部分都是用vue或者react开发习惯了组件化的方式,所以我这边打算用webpack5配置一个可以打包传统jQuery多页面应用想法通过配置postcss给css自动加上前缀通过配置babel把e......
  • 配置elk插件安全访问elk前台页面
    编辑els配置文件vimelasticsearch.yml,添加以下配置文件用elk用户,启动els服务关闭防火墙,查看els启动是否成功,通过是否启动java进程来判断或者通过查看是否启动9200和9300端口来判断是否启动交互模式启动密码配置文件interactive表示交互模式提示输入用户密码,全部输......
  • 1264. 页面推荐#奇怪,非常奇怪,谁能解决这个问题!!!!!!!!!!!!!!!!!!!!!!!
    目录题目链接题目和要求问题1234当时我人就麻了,因为我非常相信我的思路没有问题56然后我就开始怀疑是力扣解释器的问题7发现都可能没有问题8910题目链接题目链接题目:链接!!!题目和要求朋友关系列表:Friendship+---------------+---------+|ColumnName|......
  • swiftui 轮播图切换
    importSwiftUIstructBanner:View{@Statevarcat=0@Statevarpage=0varbody:someView{ZStack{Color.gray.edgesIgnoringSafeArea(.all)VStack{......
  • swiftui轮播图
    importSwiftUIstructPost:Identifiable{varid=UUID().uuidStringvarpostImage:String}importSwiftUIstructSnapCarousel<Content:View,T:Identifiable>:View{varcontent:(T)->Contentvarlist:[T]/......
  • mse~路由实现某个页面的灰度功能
    起因我有个网站A【蓝色服务】,要对网站A进行改版【绿色服务】,其中用户中心已经改完了,希望当用户访问时,如果http请求头中包含isGroup,并且isGroup=1时,去新的绿色服务,反之就还是去蓝色服务。前提蓝绿服务,域名是同一个,如lind.gray.com蓝绿服务,各个页面的URL是同一个用户测在访问U......