我有一个覆盖按钮,我希望在我们不在第一个视图中的情况下出现!
之后,我希望用户使用此覆盖层导航表单
但是,我无法使叠加层有条件地格式化,因此如果“视图> 1”,它就会执行此操作,所以它看起来像这样。
'''
//
// ContentView.swift
// PartyUp
//
// Created by Aarya Chandak on 3/9/22.
//
import SwiftUI
struct PartyPage: View {
@State private var viewModel = User.userList
@State var views = 0
@State private var cur = 0;
private var pages = 3;
var body: some View {
if(viewModel.isEmpty) {
VStack {
RSVPView()
}
} else {
ZStack {
VStack{
Text("Lets plan something!").padding()
Button(action: {views += 1}, label: { Image(systemName: "person.badge.plus")
})
}
if(views == 1) {
InviteScreen()
}
if(views == 2) {
PlanningScreen()
}
if(views == 3) {
ReviewScreen()
}
}
.overlay(
Button(action: {
withAnimation(.easeInOut) {
if(views <= totalPages){
views += 1;
}
else {
views = 0
}
}
}, label: {
Image(systemName: "chevron.right")
.font(.system(size:20, weight: .semibold))
.frame(width: 33, height: 33)
.background(.white)
.clipShape(Circle())
// Circuclar Slide
.overlay(
ZStack{
Circle()
.stroke(Color.black.opacity(0.04), lineWidth: 4)
.padding(-3)
Circle()
.trim(from: 0.0, to: CGFloat(views/pages))
.stroke(Color.white, lineWidth: 4)
.rotationEffect(.init(degrees: -90))
}
.padding(-3)
)
}
),alignment: .bottom).foregroundColor(.primary)
}
}
'''
Run Code Online (Sandbox Code Playgroud)
vad*_*ian 24
几乎所有修饰符都接受不改变nil
的值。
所以基本上你可以写
.overlay(views > 1 ? Button(action: { ... }, label: { ... }) : nil)
Run Code Online (Sandbox Code Playgroud)
如果将按钮提取到额外的视图结构中,它会变得更加清晰。
归档时间: |
|
查看次数: |
5867 次 |
最近记录: |