Answers for "swiftui with animation if"

0

swiftui animation

//You can use the withAnimation {} function

//An example of this includes

...

@State var rotation = 0

HStack {
  Image("cat.jpeg")
  	.rotationEffect(Angle(Double(rotation)!))
  	//This is to turn the image by a certain amount of degrees
  Button("Turn Image Slowly") {
      withAnimation(.easeInOut, duration: 2) {
          rotation = 90
      }
   }
}

//Here, (ignore the easeInOut for now), the withAnimation function
//Makes it so that it takes 2 seconds for the value of rotation to go from 0 to 90
//Thus, it turns the Image from 0 to 90 degrees in 2 seconds
Posted by: Guest on August-13-2021

Code answers related to "Swift"

Browse Popular Code Answers by Language