To anyone that whose transition works only with the deprecated code. Here's what to do : 1. Wrap the Button's `showView.toggle()` in a withAnimation() and you pass in the type of animation (.easeInOut) there Button("BUTTON") { withAnimation(.easeInOut){ showView.toggle() } 2. Remove the `.animation(.easeInOut)` from `RoundedRectangle()`. You don't need it. And keep only the `.transition(.slide)`
This does work, but is not really a solution. There may be scenarios in which using the "animation" modifier is prefered over the withAnimation() method.
@@nancyjain6259 It doesn't work, removed it from the Rounded rectangle and instead putting the animation directly on the button as described by OP works.
Works... Add a ZStack in the Previews struct TransitionBootcamp_Previews: PreviewProvider { static var previews: some View { ZStack { TransitionBootcamp() } } } Add your animation in the Button Button("Button") { withAnimation { showView.toggle() } } And the RoundedRectangle... if showView { RoundedRectangle(cornerRadius: 30) .frame(height: UIScreen.main.bounds.height * 0.5) .transition(.slide) } Seems 16.2 fixed a bunch of issues.
For anyone having issues with the transitions only working on the outward (false) click, the issue is that there is a bug in the renderer for the Preview. A workaround for this is to embed your View in a VStack in the preview as below: struct TransitionBootcamp_Previews: PreviewProvider { static var previews: some View { VStack { TransitionBootcamp() } } }
Xcode 14.3.1 version have this issue, Playgrounds 4.3.1 is working, Simulator also working. Simulator need you change project's ContentView "struct ContentView: View { var body: some View { TransitionBootcamp() } }"
@SwiftfulThinking regarding your question at 8:15: When you use .animation(.easeInOut, value: showView), you're specifying that the animation should only occur when the showView value changes. However, SwiftUI's transition modifiers, such as .transition, work based on view insertion and removal, not changes to a single property like showView.
For anyone watching this with Xcode 15.4, Wrapping up the state variable in a "withAnimation()" potentially avoids all problems that you may run just following the tutorial, since the .animation modifier has been changed a bit. My code: ZStack (alignment : .bottom) { VStack { Button("BUTTON") { withAnimation{ showView.toggle() } } Spacer() } if showView { RoundedRectangle(cornerRadius: 30) .frame(height: UIScreen.main.bounds.height * 0.5) .transition(.opacity) //.opacity(showView ? 1.0 : 0.0) //.animation(.easeInOut, value: showView) } } .ignoresSafeArea(edges: .bottom)
In reference to the bug in Xcode mentioned below. It seems to be a problem with the canvas. If you add a VStack to your preview, the transitions will work as normal. For this tutorial, it would look something like this: } struct TransitionsBootcamp_Previews: PreviewProvider { static var previews: some View { ZStack { TransitionsBootcamp() } } }
Enjoying the tutorials. Unless I'm missing something, I've encountered a bug in Xcode 13.3.1. The insertion transition (even on standard transitions without .asymmetric) is not showing in preview, but removal transition is. But when I ran in the simulator the transitions showed. Weird, but wanted to share in case anyone else saw this. Wasted a couple hours trying to run down the problem. Also - got around the depreciation problem with code below - note when the code below is run, the scale insertion transition doesn't run, but the scale does execute on removal. Running in the simulator, though, works fine: Button("Button") { withAnimation(.linear(duration: 0.5)) { showView.toggle() } } if showView { RoundedRectangle(cornerRadius: 30) .frame(height: UIScreen.main.bounds.height * 0.5) .transition(AnyTransition.scale) }
Hey Nick, really awesome series! I am learning a lot from you. One thing I noticed, it seems like with the latest version of xcode and swiftui things got changed, .animation is now deprecated and the suggestion is to either wrap the state value in withAnimation, or to add a second parameter to .animation(.spring(), value: ...) and I am not sure what the value should be here, I tried with showView, but this completely breaks the transition.
Hi Nick. You are a such good teacher, I've been learning so much with you and your videos, they are just so easy to understand and extremely well made. This bootcamp is definitely keeping me motivated to be a better developer every day more and more. I do have a question for you though, it is possible to animate SF symbols and icons ?? if so, how should I do it? Thank you so much and keep up the great work!!
Fantastic series, Nick! For some reason, animating transitions appears to be problematic with the latest XCode beta 14: scale and opacity animations continue to work as you showed in your videos when. view transitions in, but move and slide do not. I tried adding AnyTransition as you showed at one point, but that did not solve it. For example, these modifiers work with your demo video: .transition(.asymmetric( insertion: .opacity, removal: .scale(scale: 0)).animation(.easeInOut)) // works .transition(.opacity.animation(.easeInOut)) // also works While these simply flash in without any animation: .transition(AnyTransition.move(edge: .bottom).animation(.default)) // fails I didn't see anything corresponding at StackOverflow, and I don't mean to give you a puzzle to solve, but I will be watching for your update to this video for ios15 to see if there's something simple I'm missing. Keep up the great work!
It really look like a "bug" in Xcode14 because removal works but insertion not. RoundedRectangle(cornerRadius: 20) .frame(maxHeight: UIScreen.main.bounds.size.height * 2 / 3) .transition(.asymmetric( insertion: .move(edge: .top).animation(Animation.easeIn), removal: .move(edge: .bottom).animation(Animation.easeOut) )) With this and Button { withAnimation { showView.toggle() } The removal works fine, but the insertion still pops in. Btw. Nick amazing job.
Hi Nick, after the update of the swiftui the comment came that the .animation will no longer be used in the future, that we have to work with withAnimations. There I discover an error or at least it doesn't work well for me. With the parameter .easeInOut, the slow entry of the subscreen comes in suddenly, but exiting the subscreen works fine. Do you have any tips on how I can tackle that problem?
I'm running Xcode Version 13.4.1 that has the '' 'animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead" warning. I ran into trouble when adding the .transition(.slide) modifier at 5:47. No error, but it didn't perform correctly in the preview canvas. I noticed though if I use the .animation(.easeInOut) modifier w/ the warning instead of the .animation(.easeInOut, value: showView) w/o the warning then everything works as it should.
same goes to me. running xcode 14.3.1 using .animation(.easeIn, value: showView) does not work, however using .animation(.easeIn) does work but it gives the warning 'animation' was deprecated in iOS 15.0 how can we use this transition without any warning?
@@syahirsuyab Here's what to do : 1. Wrap the Button's `showView.toggle()` in a withAnimation() and you pass in the type of animation (.easeInOut) there Button("BUTTON") { withAnimation(.easeInOut){ showView.toggle() } 2. Remove the `.animation(.easeInOut)` from `RoundedRectangle()`. You don't need it. And keep only the `.transition(.slide)`
Thank you so much for this great content. I have a question though. When I do this examples with .animation(), I get this warning: 'animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead. But if I add animation(_:value:) and I put showView in the value parameter, then the transition doesn't work. What would be the proper way to do this?
@@SwiftfulThinking Thank you very much for your reply Nick. I did what you told me but the result is not what we expected. The animation only works when showView changes from true to false. This is my code: ZStack(alignment: .bottom) { VStack { Button("BUTTON:") { withAnimation(.easeInOut) { showView.toggle() } } Spacer() } if showView { RoundedRectangle(cornerRadius: 30) .frame(height: UIScreen.main.bounds.height * 0.5) .transition(.slide) } } .ignoresSafeArea(edges: .bottom) Am I doing something wrong here?
@@andresraigoza2082 hi, i think animations not working properly on canvas. try running the simulator instead. it worked for me. I will be very happy if you come back.
Hi Nick, I really like your bootcamp videos. I just thought of something in this video. Why did we add ZStack, I did it without adding it, it worked the same way. Is there anything I missed?
Hey, great vid. when i use .frame(height: UIScreen.main.bounds.height = 0.5) it throws two errors about height being a get only property and it not being able to convert () to CGFloat. Does this have to do with .main being deprecated?
Thank you so much for this great video. When I do these examples with UIScene, I get this error: " Type 'UIScene' has no member 'main'", I using Xcode13.2, IOS15.2. How can I fix error?
Love your content bro ! Do you have like a Discord Server or some where the community can ask questions or do some projects together ? thank you for all the hard work !
@@SwiftfulThinking Hey Nick, I watch your videos about every day, and every time I come on, there's at least another 200 subscribers, I think you had 2.7K When I found your channel! Whats the bet you're going to reach 10K by the New year???
So transition works with an animation ? I tried to remove the animation, but the transition doesn't work.. This is the cases for all transitions ? And thank you for your amazing bootcamp !!
Hi Hugo! Thanks for the comment :) and yes, transitions are animations that occur when a View is being drawn on or off the screen. We need to use transition with animation to make it work!
Hello Team, I was trying transition inside if condition, but its not showing effects.. Anyone can help ? refer below code if showView { RoundedRectangle(cornerRadius: 10) .frame(height: UIScreen.main.bounds.height / 2) .transition(.slide) .animation(.easeInOut, value: showView) }
Idk if you're still working on this but the ".animation" modifier doesn't work. Comment it and just embed the showView.toggle() inside a withAnimation() tag as follows: var body: some View { ZStack (alignment : .bottom) { VStack { Button("BUTTON") { withAnimation{ showView.toggle() } } Spacer() } if showView { RoundedRectangle(cornerRadius: 30) .frame(height: UIScreen.main.bounds.height * 0.5) .transition(.slide) //.opacity(showView ? 1.0 : 0.0) //.animation(.easeInOut, value: showView) } } .ignoresSafeArea(edges: .bottom) }
how do you make your screen perform an automatic removal. more like a flash on the screen. like when you double tap on a video on instagram. the heart shows and disapears in about 1.5 seconds
Hey Rasheed, the easiest solution for this would be to use a DispatchQueue with a delay, where you set "animate" to true and then after a few seconds delay, set "animate" to false.... or something like this.
To anyone that whose transition works only with the deprecated code. Here's what to do :
1. Wrap the Button's `showView.toggle()` in a withAnimation() and you pass in the type of animation (.easeInOut) there
Button("BUTTON") {
withAnimation(.easeInOut){
showView.toggle()
}
2. Remove the `.animation(.easeInOut)` from `RoundedRectangle()`. You don't need it. And keep only the `.transition(.slide)`
This does work, but is not really a solution.
There may be scenarios in which using the "animation" modifier is prefered over the withAnimation() method.
I LOVE YOUUUUUUUUUUUUUUU!!!!!!
That worked - thanks!
i tried using .animation(.easeInOut, value: showView), but not working as expected
@@nancyjain6259 It doesn't work, removed it from the Rounded rectangle and instead putting the animation directly on the button as described by OP works.
My apps after watching this:
Transitions
Transitions Everywhere!
Thanks again Nick! These videos are awesome!
Haha yes, transitions everywhere! They are so powerful.
Works...
Add a ZStack in the Previews
struct TransitionBootcamp_Previews: PreviewProvider {
static var previews: some View {
ZStack {
TransitionBootcamp()
}
}
}
Add your animation in the Button
Button("Button") {
withAnimation {
showView.toggle()
}
}
And the RoundedRectangle...
if showView {
RoundedRectangle(cornerRadius: 30)
.frame(height: UIScreen.main.bounds.height * 0.5)
.transition(.slide)
}
Seems 16.2 fixed a bunch of issues.
I was trying to find this answer everywhere. It works great, thank you!
For anyone having issues with the transitions only working on the outward (false) click, the issue is that there is a bug in the renderer for the Preview. A workaround for this is to embed your View in a VStack in the preview as below:
struct TransitionBootcamp_Previews: PreviewProvider {
static var previews: some View {
VStack {
TransitionBootcamp()
}
}
}
tnx bro its help me)
@@explosivevibe635 thanks man ! helped me a lot !
This worked in combination with the withAnimation Button suggestion from John G.
Xcode 14.3.1 version have this issue, Playgrounds 4.3.1 is working, Simulator also working. Simulator need you change project's ContentView
"struct ContentView: View {
var body: some View {
TransitionBootcamp()
}
}"
thanks bro it's helpful for me
@SwiftfulThinking regarding your question at 8:15: When you use .animation(.easeInOut, value: showView), you're specifying that the animation should only occur when the showView value changes. However, SwiftUI's transition modifiers, such as .transition, work based on view insertion and removal, not changes to a single property like showView.
For anyone watching this with Xcode 15.4,
Wrapping up the state variable in a "withAnimation()" potentially avoids all problems that you may run just following the tutorial, since the .animation modifier has been changed a bit.
My code:
ZStack (alignment : .bottom) {
VStack {
Button("BUTTON") {
withAnimation{
showView.toggle()
}
}
Spacer()
}
if showView {
RoundedRectangle(cornerRadius: 30)
.frame(height: UIScreen.main.bounds.height * 0.5)
.transition(.opacity)
//.opacity(showView ? 1.0 : 0.0)
//.animation(.easeInOut, value: showView)
}
}
.ignoresSafeArea(edges: .bottom)
Why transition is not working when i called .animation modifier but using withAnimation it worked?
In reference to the bug in Xcode mentioned below. It seems to be a problem with the canvas. If you add a VStack to your preview, the transitions will work as normal. For this tutorial, it would look something like this:
}
struct TransitionsBootcamp_Previews: PreviewProvider {
static var previews: some View {
ZStack {
TransitionsBootcamp()
}
}
}
Bruh I can't tell you how much time I spent searching for why my animation wasn't being applied on the transition. Thank you!
Enjoying the tutorials. Unless I'm missing something, I've encountered a bug in Xcode 13.3.1. The insertion transition (even on standard transitions without .asymmetric) is not showing in preview, but removal transition is. But when I ran in the simulator the transitions showed. Weird, but wanted to share in case anyone else saw this. Wasted a couple hours trying to run down the problem.
Also - got around the depreciation problem with code below - note when the code below is run, the scale insertion transition doesn't run, but the scale does execute on removal. Running in the simulator, though, works fine:
Button("Button") {
withAnimation(.linear(duration: 0.5)) {
showView.toggle()
}
}
if showView {
RoundedRectangle(cornerRadius: 30)
.frame(height: UIScreen.main.bounds.height * 0.5)
.transition(AnyTransition.scale)
}
Woo Hoo! Half way through!
Hi Nick thank you for this lectures. They are very helpful for me.🙂
Hey Nick, really awesome series! I am learning a lot from you. One thing I noticed, it seems like with the latest version of xcode and swiftui things got changed, .animation is now deprecated and the suggestion is to either wrap the state value in withAnimation, or to add a second parameter to .animation(.spring(), value: ...) and I am not sure what the value should be here, I tried with showView, but this completely breaks the transition.
Yeah, I'm having the same issue
The second one didn't work and instead wrapping the state value was the best solution for me here.
Hi Nick. You are a such good teacher, I've been learning so much with you and your videos, they are just so easy to understand and extremely well made. This bootcamp is definitely keeping me motivated to be a better developer every day more and more. I do have a question for you though, it is possible to animate SF symbols and icons ?? if so, how should I do it? Thank you so much and keep up the great work!!
Hi buddy, just simply change the rectangle to Image(systemName: "SF Symbol you want") and that should work. remember to add .resizable()
@@zacharyyong4095 Thank you!
Super awesome video
If I get a job, I promise I will buy you a lot of coffee with my first paycheck. You have my word!
*When you get a job
@@SwiftfulThinking Oh, now you made my day
This is great, but definitely had to jump through some hoops to get it to work in 15.x
Great video. IMO, transition is about direction, while animation is about timing (transition itself is always instant)
Fantastic series, Nick! For some reason, animating transitions appears to be problematic with the latest XCode beta 14: scale and opacity animations continue to work as you showed in your videos when. view transitions in, but move and slide do not. I tried adding AnyTransition as you showed at one point, but that did not solve it.
For example, these modifiers work with your demo video:
.transition(.asymmetric(
insertion: .opacity,
removal: .scale(scale: 0)).animation(.easeInOut)) // works
.transition(.opacity.animation(.easeInOut)) // also works
While these simply flash in without any animation:
.transition(AnyTransition.move(edge: .bottom).animation(.default)) // fails
I didn't see anything corresponding at StackOverflow, and I don't mean to give you a puzzle to solve, but I will be watching for your update to this video for ios15 to see if there's something simple I'm missing. Keep up the great work!
It really look like a "bug" in Xcode14 because removal works but insertion not.
RoundedRectangle(cornerRadius: 20)
.frame(maxHeight: UIScreen.main.bounds.size.height * 2 / 3)
.transition(.asymmetric(
insertion: .move(edge: .top).animation(Animation.easeIn),
removal: .move(edge: .bottom).animation(Animation.easeOut)
))
With this and
Button {
withAnimation {
showView.toggle()
}
The removal works fine, but the insertion still pops in.
Btw. Nick amazing job.
After digging in, it's an issue with the Canvas display inside Xcode 14
If one using the simulor it works as supposed.
Hi Nick,
after the update of the swiftui the comment came that the .animation will no longer be used in the future, that we have to work with withAnimations.
There I discover an error or at least it doesn't work well for me. With the parameter .easeInOut, the slow entry of the subscreen comes in suddenly, but exiting the subscreen works fine. Do you have any tips on how I can tackle that problem?
Wow...Thanks man
Thanks for watching Sadeq!
Great tutorial Nick. Wondering how you got the parameters to color white on Xcode Settings? Thanks
amazing! thanks a lot!
You rock, man
I think You should re-upload this tutorial, the .slide is not working, animation is changed , and main will be deprecated
I'm running Xcode Version 13.4.1 that has the '' 'animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead" warning. I ran into trouble when adding the .transition(.slide) modifier at 5:47. No error, but it didn't perform correctly in the preview canvas. I noticed though if I use the .animation(.easeInOut) modifier w/ the warning instead of the .animation(.easeInOut, value: showView) w/o the warning then everything works as it should.
thank you
same goes to me. running xcode 14.3.1
using .animation(.easeIn, value: showView) does not work, however
using .animation(.easeIn) does work but it gives the warning 'animation' was deprecated in iOS 15.0
how can we use this transition without any warning?
@@syahirsuyab Here's what to do :
1. Wrap the Button's `showView.toggle()` in a withAnimation() and you pass in the type of animation (.easeInOut) there
Button("BUTTON") {
withAnimation(.easeInOut){
showView.toggle()
}
2. Remove the `.animation(.easeInOut)` from `RoundedRectangle()`. You don't need it. And keep only the `.transition(.slide)`
Thank you so much for this great content. I have a question though. When I do this examples with .animation(), I get this warning: 'animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead. But if I add animation(_:value:) and I put showView in the value parameter, then the transition doesn't work. What would be the proper way to do this?
You can get rid of the .animation() and instead perform the action withAnimation. ...
withAnimation(.easeInOut) {
showView.toggle()
}
@@SwiftfulThinking Thank you very much for your reply Nick. I did what you told me but the result is not what we expected. The animation only works when showView changes from true to false. This is my code:
ZStack(alignment: .bottom) {
VStack {
Button("BUTTON:") {
withAnimation(.easeInOut) {
showView.toggle()
}
}
Spacer()
}
if showView {
RoundedRectangle(cornerRadius: 30)
.frame(height: UIScreen.main.bounds.height * 0.5)
.transition(.slide)
}
}
.ignoresSafeArea(edges: .bottom)
Am I doing something wrong here?
@@andresraigoza2082 hi, i think animations not working properly on canvas. try running the simulator instead. it worked for me. I will be very happy if you come back.
@@surakadotme Yes you are right!!! This seems to be a canvas bug, thank you so much 😀
@@andresraigoza2082 I'm really glad it worked :))
Hi Nick,
I really like your bootcamp videos.
I just thought of something in this video.
Why did we add ZStack, I did it without adding it, it worked the same way.
Is there anything I missed?
I think it was a bug on older iOS that may be fixed now
You are the best bro wow
Top Notch Video 👍
Cool bro....😉
transition(.slider) is bug. How fix? Cotent not started of left side to right.
ZStack { VStack{...} ObjectView().transition(.slider) }.animation(.spirit) is great works!! ZStack need animated and object in stack need transition
it says .main will be deprecated in the future, What can We use instead?
Hey, great vid. when i use .frame(height: UIScreen.main.bounds.height = 0.5)
it throws two errors about height being a get only property and it not being able to convert () to CGFloat. Does this have to do with .main being deprecated?
I think you mean “ * 0.5” and not “= 0.5”
This error likely means you have a typo bc it thinks you added a function where it should be a CGFloat
@@SwiftfulThinking oh wow thank you lmao
Thank you so much for this great video. When I do these examples with UIScene, I get this error: " Type 'UIScene' has no member 'main'", I using Xcode13.2, IOS15.2. How can I fix error?
Love your content bro !
Do you have like a Discord Server or some where the community can ask questions or do some projects together ?
thank you for all the hard work !
Hey Alperen! I don't... yet. I'm planning on making one soon though! haha I don't have that many subs yet 🥺
@@SwiftfulThinkingstarting small while becoming a bigger Community 👍🏽😁
@@SwiftfulThinking Hey Nick, I watch your videos about every day, and every time I come on, there's at least another 200 subscribers, I think you had 2.7K When I found your channel! Whats the bet you're going to reach 10K by the New year???
@@hourglassentertainment237 Haha we're slowly growing 🙃
Nick, transition is working to slide in but not sliding out!!! Help
Oh no!
Resolved, thank you
So transition works with an animation ? I tried to remove the animation, but the transition doesn't work.. This is the cases for all transitions ?
And thank you for your amazing bootcamp !!
Hi Hugo! Thanks for the comment :) and yes, transitions are animations that occur when a View is being drawn on or off the screen. We need to use transition with animation to make it work!
The transition modifier also comes with a withAnimation instance method.
top lessons)
Grear
How can I have corner radius only on top and not bottom too. I use iPhone 8.
👍🔥
8:15 .opacity is not working on the canvas. In the simulator it works as expected
Hello Team,
I was trying transition inside if condition, but its not showing effects..
Anyone can help ?
refer below code
if showView {
RoundedRectangle(cornerRadius: 10)
.frame(height: UIScreen.main.bounds.height / 2)
.transition(.slide)
.animation(.easeInOut, value: showView)
}
Idk if you're still working on this but the ".animation" modifier doesn't work.
Comment it and just embed the showView.toggle() inside a withAnimation() tag as follows:
var body: some View {
ZStack (alignment : .bottom) {
VStack {
Button("BUTTON") {
withAnimation{
showView.toggle()
}
}
Spacer()
}
if showView {
RoundedRectangle(cornerRadius: 30)
.frame(height: UIScreen.main.bounds.height * 0.5)
.transition(.slide)
//.opacity(showView ? 1.0 : 0.0)
//.animation(.easeInOut, value: showView)
}
}
.ignoresSafeArea(edges: .bottom)
}
how do you make your screen perform an automatic removal. more like a flash on the screen. like when you double tap on a video on instagram. the heart shows and disapears in about 1.5 seconds
Hey Rasheed, the easiest solution for this would be to use a DispatchQueue with a delay, where you set "animate" to true and then after a few seconds delay, set "animate" to false.... or something like this.
Nick , I am in progress and the favor return to you , thank you 🤎🤎