
//
// ContentView.swift
// GuidePage
//
// Created by antu on 2020/11/29.
//
importSwiftUI
structContentView: View {
@StatevarpageNumber = 1
@StatevarperiousOffset: CGSize = CGSize(width: UIScreen.main.bounds.width, height: 0)
@Statevaroffset: CGSize = CGSize(width: UIScreen.main.bounds.width, height: 0)
varbody:someView {
letdragGesture = DragGesture()
.onChanged { (value)in
self.offset.width =self.periousOffset.width + value.translation.width
}
.onEnded { (value)in
ifabs(value.translation.width) < 50 {
self.offset.width =self.periousOffset.width
}else{
ifvalue.translation.width > 0 &&self.pageNumber > 1 {
periousOffset.width += UIScreen.main.bounds.width
pageNumber -= 1
offset.width = periousOffset.width
}elseifvalue.translation.width < 0 && pageNumber < 3 {
periousOffset.width -= UIScreen.main.bounds.width
pageNumber += 1
offset.width = periousOffset.width
}else{
offset.width = periousOffset.width
}
}
}
returnVStack(alignment: .center, spacing:nil, content: {
HStack {
PageView(title: "Explore1")
PageView(title: "Explore1")
PageView(title: "Explore3")
}
.offset(x: offset.width, y: 0)
.gesture(dragGesture)
.animation(.interpolatingSpring(stiffness: 100, damping: 10))
VStack {
PageIndicator(pageNumber: $pageNumber)
Button(action: {
ifpageNumber == 3 {
}else{
periousOffset.width -= UIScreen.main.bounds.width
pageNumber += 1
offset.width = periousOffset.width
}
}) {
Text(pageNumber == 3 ? "开始" : "跳过")
.foregroundColor(pageNumber == 3 ? .white : .orange)
.multilineTextAlignment(.trailing)
.frame(width: UIScreen.main.bounds.width - 60, height: 50, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
.background(pageNumber == 3 ? Color.orange : Color.white)
.font(.system(size: 16))
.cornerRadius(25)
.animation(.easeIn)
}
}
.padding(.bottom, 20)
})
}
}
structContentView_Previews: PreviewProvider {
staticvarpreviews:someView {
ContentView()
}
}
structPageView: View {
varimageName = "image"
vartitle = "Exolore"
varsubTitle = "Variety xxxxxx xxxxxx xxxxxxx xxxxxx"
varslogen = "YUMMM !"
varbody:someView {
VStack {
Spacer()
Image(imageName)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 150, height: 150, alignment: .center)
.clipShape(Circle())
.shadow(color: Color.gray.opacity(0.5), radius: 10, x: 0.0, y: 10.0)
Text(title)
.font(.system(size: 36))
.bold()
.padding(.top, 70)
Text(subTitle)
.multilineTextAlignment(.center)
.foregroundColor(.gray)
.padding(.top, 20)
.padding(.bottom, 20)
Text(slogen)
.font(.system(size: 22))
.foregroundColor(.orange)
Spacer()
}
.frame(width: UIScreen.main.bounds.width)
}
}
structPageIndicator: View {
@BindingvarpageNumber : Int
varbody:someView {
HStack {
Circle()
.frame(width: 10, height: 10)
.foregroundColor(pageNumber == 1 ? .orange : .gray)
Circle()
.frame(width: 10, height: 10)
.foregroundColor(pageNumber == 2 ? .orange : .gray)
Circle()
.frame(width: 10, height: 10)
.foregroundColor(pageNumber == 3 ? .orange : .gray)
}
.padding(.bottom, 60)
}
}
网友评论