SwiftUI_visionOS_Note

Transition

Dec 30, 2023
Transition
  • Regular animations render the objects on the screen already.
  • If we have an object that isn’t on the screen, we use transition.
  • Required conditional logics to use transition.
    • Due to that transition is under utilized.
 

1. Create a button and a rounded rectangle with half-height of canvas size.

  1. We will use GeometryReader to make it half-canvas size.
    1. Wrap the content with GeometryReader{ geometry in …}
    2. Set the height with geometry.size.height * 0.5
 
 

2. Add a animation

  1. Add a boolean variable.
    1. use @State to create a boolean
  1. Add withAnimation function in button.
    1. withAnimation(Animation.default){boolean.toggle()}
  1. add boolean to see the animation.
 
 
 

3. Change the opacity animation to opacity transition.’

  1. We wrap the rounded rectangle with if Statement
  1. add .transition(.opacity) instead of .opacity
 
 
Callout icon'
List of transitions to use

//                        .transition(.scale)

//                        .transition(.slide)

//                        .transition(.move(edge: .top))

//                        .transition(.opacity)

 

4. We can customize the transition animation by using AnyTransition

  1. instead of .opacity , we can wrap it with Anytransition.opacity.animation(.easeIn(duration: 1))
 
 

5. We can add a entering and exiting transition.

  1. use .asymmetric
 
 
 
 

Use .transition to animate an object's entry and exit.

❓When should we use .animation and .transition?

💛 Playing with the .asymmetric transition effect can be fun.

🫥 So, which one do we use the most?

#visionOS #applevisionpro #swiftUI #appdevelopment

You might also like

BlogPro logo
Made with BlogPro