纯SwiftUI登录,注册,注册流程,可以吗?

编程入门 行业动态 更新时间:2024-10-24 09:29:33
本文介绍了纯SwiftUI登录,注册,注册流程,可以吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是ios开发的新手,我直接使用SwiftUI和Xcode12.我试图从登录屏幕了解登录流程,在输入凭据后,您会看到一个tabview屏幕.

Im new to ios development and I have come straight into SwiftUI and Xcode 12. I'm trying to understand the flow for login from a login screen that after you input your credentials you are presented with a tabview screen.

应用首次加载时,会显示登录信息,登录成功后会返回并保存服务器中的令牌,然后进一步启动应用程序会检查令牌并显示适当的视图

When the app first loads, its presented with the login and after login is successful the token from the server is returned and saved and further starting of the app checks for token and displays appropriate view

WindowGroup { if token == nil { LoginView() } else { TabView() } }

我的问题是在应用程序内对服务器进行了调用,结果显示了无效的令牌,我想将用户发送回登录屏幕,但是已经设置了TabView.我还使用了NavigationView,并且不希望登录屏幕上的后退按钮可用.

My problem is within the app a call is made to the server and the result shows invalid token, I want to send the user back to the login screen, but TabView had already been set. I also use the NavigationView and dont want the back button available on the login screen.

我发现的教程通常需要使用appDelegate和sceneDelegate,但我认为如果没有这些内容,这是有可能的

The tutorials I have found generally require the use of appDelegate and sceneDelegate but I would assume its possible without these anymore

感谢您的帮助

推荐答案

将UI分层是最干净的IMO.在应用程序主界面中,我将创建不同的层,这些层将负责在显示下一层之前执行某些操作.看看下面的示例代码...

Layering your UI would be the cleanest IMO. In you're app main I would create different layers that would be responsible for doing something before the next layer is shown. Take a look at the below sample code...

WindowGroup { ZStack { Color.background.edgesIgnoringSafeArea(.all) // this layer will take care of sign up and authentication AuthenticationLayer { account: AccountStore in // city select will take care of a default location for the app CitySelectLayer { city, citySelect in // this layer will be responsible for displaying overlaid media MediaLayer { mediaVM in // main screen TabbedScreen() .environmentObject(account) .environmentObject(city) .environmentObject(citySelect) .environmentObject(mediaVM) } } } } }

我尝试了几种不同的方法,这是最干净的方法.图层视图看起来像这样...

I've tried several different methods and this is the cleanest. The layer view would look something like this...

struct MediaLayer<Content: View> : View { // content let content : (ImagesOverlayVM) -> Content // view model @StateObject var viewModel = ImagesOverlayVM() var exitButton : some View { Button(action: viewModel.dismissImages) { Image(systemName: "xmark.circle") .font(.system(.title3, design: .rounded)) .foregroundColor(.secondary) } } var header : some View { HStack { exitButton Spacer() }.padding() } var loadingView : some View { Image(systemImage: .radiowaves) .resizable() .aspectRatio(contentMode: .fit) .frame(width: 32, height: 32) .foregroundColor(.secondary) .spin() } var placeholder : some View { Image(systemName: "photo") .resizable() .aspectRatio(contentMode: .fit) .frame(width: 32, height: 32) .foregroundColor(.secondary) } func tabView(images: [S3ImageLoader]) -> some View { TabView { ForEach(images) { vm in S3ImageView(viewModel: vm, contentMode: .fit) { loadingView } placeholder: { placeholder } } }.tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic)) } var body : some View { ZStack { content(viewModel) .isHidden(viewModel.images != nil) if let images = viewModel.images { VStack(spacing: 0) { header tabView(images: images) header .hidden() } } } }

}

更多推荐

纯SwiftUI登录,注册,注册流程,可以吗?

本文发布于:2023-11-17 03:00:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608564.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:流程   SwiftUI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!