SwiftUI - View is Wrong on iPad - swift

I followed a tutorial to create a navigation menu, but I have a problem. On iPhone it is looks amazing, but on iPad I can't figure the problem.
It seems that I have a "back" button under the menu-button and If I press on it, it will show (kind-off) the page.
ScreenShoots will tell more.
Screens: https://imgur.com/a/i1Xv32t
Here is the code:
Main View
import SwiftUI
struct MainView: View {
#State var selectedTab = "Home"
#State var showMenu = false
#Environment(\.colorScheme) var colorScheme
var body: some View {
ZStack {
Color("myblue")
.ignoresSafeArea()
// Side Menu
ScrollView(getRect().height < 750 ? .vertical : .init(), showsIndicators: false, content: {
SideMenu(selectedTab: $selectedTab)
})
ZStack {
if colorScheme == .dark {
Color.black
.opacity(0.5)
.cornerRadius(showMenu ? 15 : 0)
.shadow(color: Color.black.opacity(0.07), radius: 5, x: -5, y: 0)
.offset(x: showMenu ? -25 : 0)
.padding(.vertical, 30)
Color.black
.opacity(0.4)
.cornerRadius(showMenu ? 15 : 0)
.shadow(color: Color.black.opacity(0.07), radius: 5, x: -5, y: 0)
.offset(x: showMenu ? -50 : 0)
.padding(.vertical, 60)
} else {
Color.white
.opacity(0.5)
.cornerRadius(showMenu ? 15 : 0)
.shadow(color: Color.black.opacity(0.07), radius: 5, x: -5, y: 0)
.offset(x: showMenu ? -25 : 0)
.padding(.vertical, 30)
Color.white
.opacity(0.4)
.cornerRadius(showMenu ? 15 : 0)
.shadow(color: Color.black.opacity(0.07), radius: 5, x: -5, y: 0)
.offset(x: showMenu ? -50 : 0)
.padding(.vertical, 60)
}
Home(selectedTab: $selectedTab)
.cornerRadius(showMenu ? 15 : 1)
}
// Scalling and Moving The View
.scaleEffect(showMenu ? 0.84 : 1)
.offset(x: showMenu ? getRect().width - 120 : 0)
.ignoresSafeArea()
.overlay(
// Menu Button
Button(action: {
withAnimation(.spring()) {
showMenu.toggle()
}}, label: {
VStack (spacing: 5) {
Capsule()
.fill(showMenu ? Color.white : Color.primary)
.frame(width: 30, height: 3)
.rotationEffect(.init(degrees: showMenu ? -50 : 0))
.offset(x: showMenu ? 2 : 0, y: showMenu ? 9 : 0)
VStack (spacing: 5) {
Capsule()
.fill(showMenu ? Color.white : Color.primary)
.frame(width: 30, height: 3)
Capsule()
.fill(showMenu ? Color.white : Color.primary)
.frame(width: 30, height: 3)
.offset(y: showMenu ? -8 : 0)
}
.rotationEffect(.init(degrees: showMenu ? 50 : 0))
}
})
.padding()
,alignment: .topLeading
)
}
}
}
struct MainView_Previews: PreviewProvider {
static var previews: some View {
MainView()
}
}
extension View {
func getRect()->CGRect {
return UIScreen.main.bounds
}
}
Home
import SwiftUI
struct Home: View {
#Binding var selectedTab: String
init(selectedTab: Binding<String>) {
self._selectedTab = selectedTab
UITabBar.appearance().isHidden = true
}
var body: some View {
// Tab View with Tabs
TabView(selection: $selectedTab) {
// Views
HomePage()
.tag("Home")
History()
.tag("History")
Notifications()
.tag("Notifications")
Settings()
.tag("Settings")
Help()
.tag("Help")
}
}
}
struct Home_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct HomePage: View {
var body: some View {
NavigationView {
Text("Home")
.font(.largeTitle)
.fontWeight(.heavy)
.foregroundColor(.primary)
.navigationTitle("Home")
}.navigationBarBackButtonHidden(true)
}
}
struct History: View {
var body: some View {
NavigationView {
Text("History")
.font(.largeTitle)
.fontWeight(.heavy)
.foregroundColor(.primary)
.navigationTitle("History")
}
}
}
struct Notifications: View {
var body: some View {
NavigationView {
Text("Notifications")
.font(.largeTitle)
.fontWeight(.heavy)
.foregroundColor(.primary)
.navigationTitle("Notifications")
}
}
}
struct Settings: View {
var body: some View {
NavigationView {
Text("Settings")
.font(.largeTitle)
.fontWeight(.heavy)
.foregroundColor(.primary)
.navigationTitle("Settings")
}
}
}
struct Help: View {
var body: some View {
NavigationView {
Text("Help")
.font(.largeTitle)
.fontWeight(.heavy)
.foregroundColor(.primary)
.navigationTitle("Help")
}
}
}

Found de issue!
Had to remove NavigationView { } from every struct XYZ: View { }.

Related

SwiftUI Animation causes binding conditional view to flash on and off

I have an issue with this setup:
ZStack {
ViewOne
if something ? ViewTwo : nil
}
.animation()
The problem is that when the animation starts, ViewTwo flashes on and off. I'm thinking it has something to do with the view re-rendering or something? But I can't quite figure it out. I've tried moving the animation around, using it on each view separately, combining it all in one view, but it always flashes when it's based on a conditional. I'd like BOTH views to animate together.
Here is a piece of reproducible code snippet.
struct ContentView: View {
#State var isAnimating: Bool
var body: some View {
ZStack {
VStack {
ForEach((1...5).reversed(), id: \.self) {_ in
ZStack {
RoundedRectangle(cornerRadius: 5)
.foregroundColor(.blue)
.frame(width: 200, height: 50)
.rotationEffect(.degrees(isAnimating == true ? 5 : 0))
isAnimating
? ButtonImage()
: nil
}
.animation(
.easeInOut(duration: 0.3)
.repeatForever(autoreverses: true)
, value: isAnimating
)
}
Button(action: {
self.isAnimating.toggle()
}, label: {
Text("Animate")
})
}
}
.rotationEffect(.degrees(isAnimating == true ? 5 : 0))
}
}
struct ButtonImage: View {
private let buttonSize: CGSize = CGSize(width: 25, height: 25)
var body: some View {
Button(action: {
// to something
}) {
Image(systemName: "flame")
.resizable()
.renderingMode(.template)
.background(Color.red)
.foregroundColor(Color.yellow)
.frame(width: buttonSize.width, height: buttonSize.height)
}
.frame(width: buttonSize.width, height: buttonSize.height)
.offset(x: -buttonSize.width / 2, y: -buttonSize.height / 2)
}
Any ideas of how to resolve this? Showing a view based on a condition, while also animating it without it flashing?
Figured out a way! Not sure if it's the best approach, but it works.
Add the animation to both views separately, then add an opacity modifier to the second view. Here is the code I used.
struct ContentView: View {
#State var isAnimating: Bool
var body: some View {
ZStack {
VStack {
ForEach((1...5).reversed(), id: \.self) {_ in
ZStack {
RoundedRectangle(cornerRadius: 5)
.foregroundColor(.blue)
.frame(width: 200, height: 50)
.rotationEffect(.degrees(isAnimating == true ? 5 : 0))
.animation(
.easeInOut(duration: 0.3)
.repeatForever(autoreverses: true)
, value: isAnimating
)
ButtonImage(isAnimating: $isAnimating)
.opacity(isAnimating ? 1 : 0)
}
}
Button(action: {
self.isAnimating.toggle()
}, label: {
Text("Animate")
})
}
}
.rotationEffect(.degrees(isAnimating == true ? 5 : 0))
}
}
struct ButtonImage: View {
private let buttonSize: CGSize = CGSize(width: 25, height: 25)
#Binding var isAnimating: Bool
var body: some View {
Button(action: {
// to something
}) {
Image(systemName: "flame")
.resizable()
.renderingMode(.template)
.background(Color.red)
.foregroundColor(Color.yellow)
.frame(width: buttonSize.width, height: buttonSize.height)
}
.frame(width: buttonSize.width, height: buttonSize.height)
.offset(x: -buttonSize.width / 2, y: -buttonSize.height / 2)
.rotationEffect(.degrees(isAnimating == true ? 5 : 0))
.animation(
.easeInOut(duration: 0.3)
.repeatForever(autoreverses: true)
, value: isAnimating
)
}
}

How to remove the cornerradius of sheets in swiftui?

Is there a way to remove the cornerRadius of a sheet? I tried it like this:
.sheet(isPresented: $showModal) {
Modal().cornerRadius(0, corners: [.topLeft, .topRight])
}
but it didn't work.
I know I can just use fullScreenCover but I still want to know if there is a solution to this.
According to my comment above you can create your own slide-in menu.
In the example below I added a close button as well as gesture control to close the view.
//
//
// SlideInMenu.swift
// SlideInMenu
//
// Created by Sebastian on 21.09.22.
//
import SwiftUI
var bounds = UIScreen.main.bounds
struct ContentView: View {
#State var selectedItem: String = ""
#State var showMenu = false
var body: some View {
ZStack() {
MainView(selectedItem: $selectedItem, showMenu: $showMenu)
.blur(radius: showMenu ? 3 : 0)
SlideView(selectedItem: $selectedItem, showMenu: $showMenu)
}
.edgesIgnoringSafeArea(.all)
}
}
struct MainView: View {
#Binding var selectedItem: String
#Binding var showMenu: Bool
var body: some View {
HStack(){
Spacer()
VStack() {
Spacer()
Text("This is your main View")
.foregroundColor(.white)
.padding()
Button(action: {
withAnimation(.linear(duration: 0.3)) {
self.showMenu.toggle()
}
}) {
Text("Show Menu")
.font(.system(size: 20, weight: .medium))
.foregroundColor(.white)
}
Spacer()
}
Spacer()
}.background(Color.blue)
}
}
struct SlideView: View {
#Binding var selectedItem: String
#Binding var showMenu: Bool
#State private var viewOffest: CGFloat = 100
#State private var offset = CGSize.zero
#State private var isDragging = false
var body: some View {
let dragGesture = DragGesture()
.onChanged { value in
withAnimation(.linear(duration: 0.2)) {
if value.translation.height >= 0 {
offset = value.translation
}
}
}
.onEnded { _ in
withAnimation(.linear(duration: 0.2)) {
isDragging = false
if offset.height > (bounds.height - viewOffest)/3 {
showMenu.toggle()
}
offset = .zero
}
}
ZStack() {
Color.black
.opacity(showMenu ? 0.5 : 0)
VStack() {
HStack() {
Spacer()
Spacer()
}
VStack(alignment: .leading) {
HStack() {
Spacer()
Text("Here is the menu")
.foregroundColor(.black)
Spacer()
}
HStack() {
Spacer()
Button(action: {
withAnimation(.linear(duration: 0.3)) {
self.showMenu.toggle()
}
}) {
Text("Close Menu")
.font(.system(size: 20, weight: .medium))
.foregroundColor(.red)
}
.padding()
Spacer()
}
Spacer()
}
.padding()
.background(Color.white)
.cornerRadius(0)
}
.offset(y: showMenu ? viewOffest + offset.height : bounds.height)
.gesture(dragGesture)
}
}
}
It is not possible for now perhaps we can in further update, nonetheless you can create your own custom view.

I'd like to use the navigation link.Newbie Wang is in the process of hair loss

I want to use Navigationlink. I've been a novice for 2 weeks since I started.I am currently learning SwiftUi.
I created "OnboredView" after watching YouTube, but I don't know how to connect "OnboredView" to "CountentView".
NavigationView(){
NavigationLink(destination: OnboardView())
I learned how to make it like this through YouTube, but I don't know what to do now. I put it here and there, but the red errors bother me.
Tell me how to connect "NavigationLink" by pressing the button on "CountentView".
I'd like to click "Chevron.Light" to move on to "OnboredView."And if possible, please let me know how I can get rid of the "onboard screen" on the second run?
I am not good at English.I'm sorry. I'm experiencing hair loss again.
import SwiftUI
struct ContentView: View {
#State private var animate: Bool = false
var body: some View {
ZStack{
ZStack{
Image("rogo1")
.resizable()
.frame(width: 75, height: 75)
.offset(y: animate ? -100 : 0)
}
ZStack{
Image("rogo2")
.resizable()
.frame(width: 75, height: 75)
.offset(y: animate ? -100 : 0)
}
VStack {
HStack {
Spacer()
Image("images (1)")
.resizable()
.frame(width: 300, height: 300)
.offset(x: animate ? 300 : 150, y: animate ? -300 : -150)
}
Spacer()
HStack {
Image("images (1)")
.resizable()
.frame(width: 400, height: 400)
.offset(x: animate ? -500 : -150, y: animate ? 500 : 150)
Spacer()
}
}
ZStack(alignment: .bottom){
GeometryReader { g in
VStack (alignment: .leading, spacing: 20){
Text("안녕하세요!")
.font(.title)
.fontWeight(.semibold)
.padding(.top, 20)
//인삿말과 회원가입
Text("기분 좋은 매일습관을 만들기 위한 앱 ( ) 입니다! 시간표와 더불어 루틴을 함께 할수
있도록 설계 되었습니다.저희 ( )와 함께 계획해봐요!")
.fontWeight(.medium)
.multilineTextAlignment(.center)//중앙으로 결집
.padding(5)
ZStack {
Button(action: {},label: {
Image(systemName: "chevron.right")
.font(.system(size:20, weight: .semibold))
.frame(width: 60, height: 60)
.foregroundColor(.black)
.background(Color.white)
.clipShape(Circle())
.overlay(
ZStack {
Circle()
.stroke(Color.black.opacity(0.04),lineWidth: 4)
Circle()
.trim(from: 0, to: 0.03)
.stroke(Color.white,lineWidth: 4)
.rotationEffect(.init(degrees: -40))
})
})
.padding(-10)
}
Spacer()
}
.frame(maxWidth: .infinity)
.padding(.horizontal, 30)
.background(Color.green)
.clipShape(CustomShape(leftCorner: .topLeft, rightCorner: .topRight,
radii: 20))
.offset(y: animate ? g.size.height : UIScreen.main.bounds.height)
}
}.frame(height: 275)
//여기까지 짤라도 됨 온보드
}
.frame(maxWidth: .infinity)
.edgesIgnoringSafeArea(.all)
.onAppear(perform: {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
withAnimation(Animation.easeOut(duration: 0.45)){
animate.toggle()
}
}
})
}
{
struct CustomShape: Shape {
var leftCorner: UIRectCorner
var rightCorner: UIRectCorner
var radii: CGFloat
func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect, byRoundingCorners:
[leftCorner,rightCorner], cornerRadii: CGSize(width: radii, height: radii))
return Path(path.cgPath)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
Group {
}
}
}
}
import SwiftUI
struct OnboardView: View {
#AppStorage("currentPage") var currentPage = 1
var body: some View {
if currentPage > totalPages {
Home()
}else{
WalkthroughScreen()
}
}
}
struct OnboardView_Previews: PreviewProvider {
static var previews: some View {
OnboardView()
}
}
struct Home: View {
var body: some View{
Text("welcome To Home!!!")
.font(.title)
.fontWeight(.heavy)
}
}
//..Walkthrough Screen..
struct WalkthroughScreen: View {
#AppStorage("currentPage") var currentPage = 1
var body: some View {
//For Slide Animation
ZStack{
//Changing Between Views..
if currentPage == 1 {
ScreenView(image: "image1", title: "Step1", detail: "", bgColor:
Color(.white))
//transition(.scale)영상에서는 넣었으나 오류가나서 사용하지 못함
}
if currentPage == 2 {
ScreenView(image: "image2", title: "Step2", detail: "", bgColor:
Color(.white))
}
if currentPage == 3 {
ScreenView(image: "image3", title: "Step3", detail: "아니 ㅡㅡ 이런 방법이 유레카",
bgColor: Color(.white))
}
}
.overlay(
Button(action: {
//changing views
withAnimation(.easeInOut){
if currentPage < totalPages {
currentPage += 1
}else{
currentPage = 1
//For app testing ONly
}
}
}, label: {
Image(systemName: "chevron.right")
.font(.system(size: 20, weight: .semibold))
.foregroundColor(.black)
.frame(width: 60, height: 60)
.clipShape(Circle())
//strclulat Slider
.overlay(
ZStack{
Circle()
.stroke(Color.black.opacity(0.04),lineWidth: 4
Circle()
.trim(from: 0, to: CGFloat(currentPage) /
CGFloat(totalPages))
.stroke(Color.green,lineWidth: 4)
.rotationEffect(.init(degrees: -99))
}
.padding(-15)
)
})
.padding(.bottom,20)
,alignment: .bottom
)
}
}
struct ScreenView: View {
var image: String
var title: String
var detail: String
var bgColor: Color
#AppStorage("currentPage") var currentPage = 1
var body: some View {
VStack(spacing:20){
HStack {
//Showing it only for first page..
if currentPage == 1{
Text("Hello Members!")
.font(.title)
.fontWeight(.semibold)
//Letter Spacing
.kerning(1.4)
}else{
//Back Butten..
Button(action: {
withAnimation(.easeInOut){
currentPage -= 1
}
}, label: {
Image(systemName: "chevron.left")
.foregroundColor(.white)
.padding(.vertical,10)
.padding(.horizontal)
.background(Color.black.opacity(0.4))
.cornerRadius(10)
})
}
Spacer()
Button(action: {
withAnimation(.easeInOut){
currentPage = 4
}
}, label: {
Text("Skip")//글자입력
.fontWeight(.semibold)//글자 폰트변경
.kerning(1.2)//글자간 간격 조정
})
}
.foregroundColor(.black)//그라운드 컬러 변경
.padding()
Spacer(minLength: 0)//수평,수직 줄바꿈
Image(image)//이미지 삽입
.resizable()//크기 확대
.aspectRatio(contentMode: .fit)//이미지 크기
Text(title)
.font(.title)//폰트 크기변경
.fontWeight(.bold)//폰트 두께 변경
.foregroundColor(.black)//색깔 변경
.padding(.top)
//Change with your Own Thing..
Text(detail)
.fontWeight(.semibold)
.kerning(1.3)//자간조정
.multilineTextAlignment(.center)//텍스트를 중앙으로 결집
Spacer(minLength: 220)//minimun Spacing When phone is reducing수직위치 조정
}
.background(bgColor.cornerRadius(10).ignoresSafeArea())
}
}
var totalPages = 3

Ternary operator issue SwiftUI

I'm using a ternary operator in my swiftui view to change the foreground color of an item.
When using this as code everything compiles normal:
Circle()
.frame(width: 10, height: 10)
.foregroundColor(item.amount < 10 ? Color.green : Color.red)
When using this, my project does not build, CPU of my Mac starts spiking, fans kicking in etc. Anyone an idea what's wrong ?
Circle()
.frame(width: 10, height: 10)
.foregroundColor(item.amount < 10 ? Color.green : (item.amount < 100 ? Color.orange : Color.red))
Complete code:
struct ContentView: View {
#ObservedObject var expenses = Expenses()
#State private var showAddExpense = false
var body: some View {
NavigationView {
List {
ForEach (expenses.items) { item in
HStack {
VStack(alignment: .leading) {
Text(item.name)
.font(.headline)
Text(item.type)
}
Spacer()
Text("€\(item.amount)")
Circle()
.frame(width: 10, height: 10)
.foregroundColor(item.amount < 10 ? Color.green : (item.amount < 100 ? Color.orange : Color.red))
}
}
.onDelete(perform: removeItem)
}
.navigationBarTitle("iExpense")
.navigationBarItems(leading: EditButton(), trailing:
Button(action: {
self.showAddExpense = true
}
) {
Image(systemName: "plus")
})
}
.sheet(isPresented: $showAddExpense) {
AddView(expenses: self.expenses)
}
}
func removeItem(at index: IndexSet) {
expenses.items.remove(atOffsets: index)
}
}
Error showing on the sheet modifier, but this one is correct.
Break body construction for smaller components, like below
ForEach (expenses.items) { item in
self.listRow(for: item) // << extract !!
}
.onDelete(perform: removeItem)
,say, to private row generator function
private func listRow(for item: Item) -> some View { // << your item type here
HStack {
VStack(alignment: .leading) {
Text(item.name)
.font(.headline)
Text(item.type)
}
Spacer()
Text("€\(item.amount)")
Circle()
.frame(width: 10, height: 10)
.foregroundColor(item.amount < 10 ? Color.green : (item.amount < 100 ? Color.orange : Color.red))
}
}

SwiftUI Side menu content view switching with animation

I've found many SwiftUI side menu tutorials on the internet, but none of them shows how to switch between content views. So I tried to create one, which seems to be work, my only problem is when I select any of the menu items, there's no transition animation between the contents (except when you select the active one in the menu).
I'd like to know, if this is a good approach and I need some help to complete the animation...
Thank you in advance!
import SwiftUI
enum PageSelector {
case home
case services
case testimonials
case contact
}
struct TestView: View {
#State private var show: Bool = false
#State private var pageSelector: PageSelector = .home
var body: some View {
ZStack {
// Background of the menu
Color.blue.edgesIgnoringSafeArea(.all)
// Menu items and content selection
VStack(alignment: .leading, spacing: 10) {
Spacer()
MenuItem(action: {
self.show.toggle()
self.pageSelector = .home
}, title: "Home", image: "chevron.right")
MenuItem(action: {
self.show.toggle()
self.pageSelector = .services
}, title: "Services", image: "chevron.right")
MenuItem(action: {
self.show.toggle()
self.pageSelector = .testimonials
}, title: "Testimonials", image: "chevron.right")
MenuItem(action: {
self.show.toggle()
self.pageSelector = .contact
}, title: "Contact", image: "chevron.right")
Spacer()
}
// Content
switchContent(show: show)
.disabled(show ? true : false)
.offset(x: show ? 300 : 0)
.rotationEffect(Angle(degrees: show ? -10 : 0))
.rotation3DEffect(Angle(degrees: show ? 40: 0), axis: (x: show ? 120 : 0, y: show ? 234 : 0, z: show ? 0 : 0))
.animation(.spring())
.edgesIgnoringSafeArea(.all)
// Menu button
VStack {
HStack {
Button(action: { self.show.toggle() }) {
MenuButton(show: $show)
}
Spacer()
}
Spacer()
}
}
}
// Switching pages (views)
func switchContent(show: Bool) -> AnyView {
switch pageSelector {
case .home:
return AnyView(HomeView())
case .services:
return AnyView(ServicesView())
case .testimonials:
return AnyView(TestiMonialsView())
case .contact:
return AnyView(HomeView())
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
struct MenuItem: View {
let action: ()->Void
let title: String
let image: String
var body: some View {
HStack {
Button(action: action) {
Image(systemName: image)
.foregroundColor(.white)
.padding(.horizontal)
.font(.footnote)
Text(title)
.foregroundColor(.white)
.font(.title)
}
Spacer()
}
}
}
struct MenuButton: View {
#Binding var show: Bool
var body: some View {
HStack {
Image(systemName: self.show ? "xmark" : "list.dash")
.frame(width: 50, height: 50)
.foregroundColor(self.show ? .blue : .white)
.background(self.show ? Color.white : Color.blue)
.cornerRadius(25)
.scaleEffect(self.show ? 0.6 : 1)
.shadow(radius: 20)
.padding()
.opacity(0.8)
.animation(.spring())
}
}
}
A sample view:
import SwiftUI
struct HomeView: View {
var body: some View {
VStack {
Text("This is Home")
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(Color.white)
}
}
struct HomeView_Previews: PreviewProvider {
static var previews: some View {
HomeView()
}
}
You need to separate the layout animation from content animations, like the following:
func switchContent(show: Bool) -> AnyView {
return AnyView( HomeSwitchView(pageSelector: self.$pageSelector))
}
}
struct HomeSwitchView: View {
#Binding var pageSelector : PageSelector
var body: some View {
var text : String?
switch pageSelector {
case .home:
text = "home"
case .services:
text = "services"
case .testimonials:
text = "testimonials"
case .contact:
text = "contact"
}
return VStack {
Text("\(text!)")
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(Color.blue)
}
}
First, remove all self.show.toggle() from MenuItems, like this:
MenuItem(action: {
self.pageSelector = .home
}, title: "Home", image: "chevron.right")
And then add onAppear modifier on switchContent(), like this:
switchContent(show: show)
.disabled(show ? true : false)
.offset(x: show ? 300 : 0)
.rotationEffect(Angle(degrees: show ? -10 : 0))
.rotation3DEffect(Angle(degrees: show ? 40: 0), axis: (x: show ? 120 : 0, y: show ? 234 : 0, z: show ? 0 : 0))
.animation(.spring())
.onAppear {
self.show = false
}
.edgesIgnoringSafeArea(.all)
Tested, this is working for me.