SwiftUI toolbarは、自作するしかないのかも 2020年1月時点
SwiftUIのTabViewの問題に自作TabView(SwiftUI製)で対処する – Qiita
import SwiftUI
struct ContentView: View {
@State var currentPage = 1
var body: some View {
ZStack {
Page1()
.opacity(currentPage == 1 ? 1 : 0)
.offset(x : currentPage == 1 ? 0 : 100)
.animation(Animation.spring())
Page2()
.opacity(currentPage == 2 ? 1 : 0)
.offset(x : currentPage == 2 ? 0 : 100)
.animation(Animation.spring())
Page3()
.opacity(currentPage == 3 ? 1 : 0)
.offset(x : currentPage == 3 ? 0 : 100)
.animation(Animation.spring())
MyTabView(currentPage: $currentPage)
}
}
}
import SwiftUI
struct ContentView: View {
@State var currentPage = 1
var body: some View {
ZStack {
Page1()
.opacity(currentPage == 1 ? 1 : 0)
.offset(x : currentPage == 1 ? 0 : 100)
.animation(Animation.spring())
Page2()
.opacity(currentPage == 2 ? 1 : 0)
.offset(x : currentPage == 2 ? 0 : 100)
.animation(Animation.spring())
Page3()
.opacity(currentPage == 3 ? 1 : 0)
.offset(x : currentPage == 3 ? 0 : 100)
.animation(Animation.spring())
MyTabView(currentPage: $currentPage)
}
}
}
import SwiftUI
struct ContentView: View {
@State var currentPage = 1
var body: some View {
ZStack {
Page1()
.opacity(currentPage == 1 ? 1 : 0)
.offset(x : currentPage == 1 ? 0 : 100)
.animation(Animation.spring())
Page2()
.opacity(currentPage == 2 ? 1 : 0)
.offset(x : currentPage == 2 ? 0 : 100)
.animation(Animation.spring())
Page3()
.opacity(currentPage == 3 ? 1 : 0)
.offset(x : currentPage == 3 ? 0 : 100)
.animation(Animation.spring())
MyTabView(currentPage: $currentPage)
}
}
}
struct MyTabView: View {
@Binding var currentPage: Int
var width = UIScreen.main.bounds.width
var body: some View {
VStack {
Spacer()
ZStack {
Rectangle()
.foregroundColor(Color.gray)
.frame(width: width, height: 88)
HStack(spacing: 88) {
Button(action: {
self.currentPage = 1
}) {
VStack {
Image(systemName: "flame")
.foregroundColor(Color.red)
.font(.system(size: 32, weight: .bold, design: .rounded))
}
}.padding(.bottom, 24)
Button(action: {
self.currentPage = 2
}) {
VStack {
Image(systemName: "bolt")
.foregroundColor(Color.yellow)
.font(.system(size: 32, weight: .bold, design: .rounded))
}
}.padding(.bottom, 24)
Button(action: {
self.currentPage = 3
}) {
VStack {
Image(systemName: "leaf.arrow.circlepath")
.foregroundColor(Color.green)
.font(.system(size: 32, weight: .bold, design: .rounded))
}
}.padding(.bottom, 24)
}
}
}.edgesIgnoringSafeArea(.bottom)
}
}