import SwiftUI
struct ContentView: View {
@State var selectedTag = 1
var body: some View {
TabView(selection: $selectedTag) {
HomeTabView().tag(1)
WeatherTabView().tag(2)
NewsTabView().tag(3)
NewsTabView2().tag(4)
NewsTabView3().tag(5)
}
.tabViewStyle(PageTabViewStyle())
.ignoresSafeArea()
}
}
struct HomeTabView: View {
var body: some View {
VStack {
Image(systemName: "music.note.house")
.scaleEffect(x: 3.0, y: 3.0)
.frame(width: 100, height: 100)
Text("HOME").font(.system(size: 40))
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(red: 0.5, green: 0.9, blue: 0.9))
.ignoresSafeArea()
}
}
struct WeatherTabView: View {
var body: some View {
VStack {
Image(systemName: "cloud.sun")
.scaleEffect(x: 3.0, y: 3.0)
.frame(width: 100, height: 100)
Text("Weather").font(.system(size: 40))
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(red: 1.0, green: 0.9, blue: 1.0))
.ignoresSafeArea()
}
}
struct NewsTabView: View {
var body: some View {
VStack {
Image(systemName: "newspaper")
.scaleEffect(x: 3.0, y: 3.0)
.frame(width: 100, height: 100)
Text("News").font(.system(size: 40))
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(red: 0.9, green: 0.9, blue: 0.8))
.ignoresSafeArea()
}
}
struct NewsTabView2: View {
@State var isShowSubViw = false
var body: some View {
GeometryReader { geometory in
ZStack {
VStack {
Image(systemName: "ant.circle.fill")
.scaleEffect(x: 3.0, y: 3.0)
.frame(width: 100, height: 100)
Text("NewsTabView2")
.font(.system(size: 40, weight: .black, design: .default))
.padding(.top, -20)
}
if isShowSubViw {
SubView()
} else {
Button(action: {
withAnimation() {
self.isShowSubViw.toggle()
}
}) {
Text("SubViewへ遷移")
.padding(.top, 200)
}
}
}
.frame(width: geometory.size.width,
height: geometory.size.height)
.background(Color.green)
.animation(.easeInOut(duration: 0.42))
}
.transition(.move(edge: .leading))
}
}
struct SubView: View {
@State var isShowSubViw = false
var body: some View {
GeometryReader { geometory in
ZStack {
if isShowSubViw {
NewsTabView2()
} else {
Button(action: {
withAnimation() {
self.isShowSubViw.toggle()
}
}) {
Text("NewsTabView2へ戻る")
}
.padding(.top, 100)
VStack {
Text("SubView")
.font(.system(size: 40, weight: .black, design: .default))
}
}
.frame(width: geometory.size.width,
height: geometory.size.height)
.background(
LinearGradient(
gradient: Gradient(colors: [Color.yellow, Color.red]),
startPoint: .init(x: 0.3, y: 0.3), // start地点
endPoint: .init(x: 0.55, y: 0.55) // end地点 。
))
.animation(.easeInOut(duration: 0.42))
}
.transition(.move(edge: .leading))
}
}
struct NewsTabView3: View {
@State var isShow: Bool = false
var body: some View {
VStack {
Image(systemName: "ladybug.fill")
.scaleEffect(x: 3.0, y: 3.0)
.frame(width: 100, height: 100)
Text("First View").font(.system(size: 30))
.padding(.bottom, 30)
Button(action: {
withAnimation {
self.isShow.toggle()
}
}) {
Text("Second View pageへ").font(.system(size: 20))
}
.fullScreenCover(isPresented: $isShow){
SomeView(isPresented: $isShow) // SomeViewビューを表示する
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.yellow)
.ignoresSafeArea()
}
}
struct SomeView: View {
// ContentViewビューの変数isShowとバインディングする
@Binding var isPresented: Bool
var body: some View {
NavigationView {
VStack {
Image(systemName: "ladybug").scaleEffect(2.0)
Text("Second View").font(.title2).padding()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(
LinearGradient(
gradient: Gradient(colors: [Color.yellow, Color.green]),
startPoint: .init(x: 0.3, y: 0.3), // start地点
endPoint: .init(x: 0.55, y: 0.55) // end地点
))
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button {
isPresented = false
} label: {
HStack {
Image(systemName:"lessthan")
.foregroundColor(.green)
Text("First Viewへ戻る")
.foregroundColor(Color.green)
}
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}