
- SwiftUI - Home
- SwiftUI - Overview
- SwiftUI vs UIkit
- SwiftUI Environment
- SwiftUI - Environment Setup
- SwiftUI - Basic Components
- SwiftUI - Building First Application
- SwiftUI Views
- SwiftUI - Views
- SwiftUI - Customize Text View
- SwiftUI - Custom Image View
- SwiftUI - Stacks
- SwiftUI Drawing Shapes
- SwiftUI - Shapes
- SwiftUI - Drawing line
- SwiftUI - Drawing Rectangle
- SwiftUI - Drawing Rounded Rectangle
- SwiftUI - Drawing Triangle
- SwiftUI - Drawing Circle
- SwiftUI - Drawing Star
- SwiftUI - Drawing Polygon
- SwiftUI - Drawing Pie chart
- SwiftUI - Using built-in shapes
- SwiftUI - Text
- SwiftUI - Text View
- SwiftUI - Text Input and Output
- SwiftUI - Color
- SwiftUI - Color
- SwiftUI - Colorpicker
- SwiftUI - Gradients
- SwiftUI - Adjust Color
- SwiftUI - Effects
- SwiftUI - Effects
- SwiftUI - Blend Effect
- SwiftUI - BLur Effect
- SwiftUI - Shadow Effect
- SwiftUI - Hover Effect
- SwiftUI - Animations
- SwiftUI - Animations
- SwiftUI - Creating Animations
- SwiftUI - Creating an Explicit Animation
- SwiftUI - Multiple Animations
- SwiftUI - Transitions
- SwiftUI - Asymmetric Transition
- SwiftUI - Custom Transition
- SwiftUI - Image
- SwiftUI - Images
- SwiftUI - Image as Background
- SwiftUI - Rotating Image
- SwiftUI - Media
- SwiftUI - View Layout
- SwiftUI - View Layout
- SwiftUI - View Size
- SwiftUI - View Spacing
- SwiftUI - View Padding
- SwiftUI - UI Controls
- SwiftUI - UI Controls
- SwiftUI - Button
- SwiftUI - CheckBox
- SwiftUI - Menubar
- SwiftUI - Toolbar
- SwiftUI - Search Bar
- SwiftUI - TextField
- SwiftUI - Slider
- SwiftUI - Toggle
- SwiftUI - Pickers
- SwiftUI - Menus
- SwiftUI - List & Tables
- SwiftUI - Lists
- SwiftUI - Static List
- SwiftUI - Dynamic List
- SwiftUI - Customize List
- SwiftUI - Tables
- SwiftUI - Forms
- SwiftUI - Forms
- SwiftUI - Breaking Forms in Sections
- SwiftUI - Event Handling
- SwiftUI - Event Handling
- SwiftUI - Gesture
- SwiftUI - Clipboard
- SwiftUI - Drag and Drop
- SwiftUI - Focus
- SwiftUI - Alert
- SwiftUI - Miscellaneous
- SwiftUI - Containers
- SwiftUI - Navigation
- SwiftUI - Notifications
- SwiftUI - Cross-Platform UI
- SwiftUI - Data
- SwiftUI - Accessibility
- SwiftUI - Framework Integration
- SwiftUI - Framework Integration
- SwiftUI - Interfacing with UIKit
- SwiftUI - Creating macOS App
- SwiftUI Useful Resources
- SwiftUI - Useful Resources
- SwiftUI - Discussion
SwiftUI - Asymmetric Transition
Asymmetric transition is a special type of transitions, using this we can specify different transitions for the appearance and disappearance of the view. For example, the appearance of the view uses a slide transition and the disappearance of the view uses an opacity transition. This method is used inside the .transition() modifier.
Syntax
Following is the syntax −
static func asymmetric(insertion: AnyTransition, removal: AnyTransition) -> AnyTransition
Parameters
This method takes the following parameters −
insertion: Represent the insertion transition for the view.
removal: Represent the removal transition for the view.
Example 1
In the following SwiftUI program, we apply an asymmetric transition to the rounded rectangle. Here the rounded rectange enters using slide transition and exits from the screen using opacity transition.
import SwiftUI struct ContentView: View { @State private var anime = false var body: some View { ZStack{ if anime{ RoundedRectangle(cornerRadius: 10) .fill(.red) .frame(width: 150, height: 100) // Here we apply asymmetric transition on the shape .transition(.asymmetric(insertion: .slide, removal: .opacity)) } }.padding(30) Button("Click Me"){ withAnimation(.default){ anime.toggle() } }.font(.title).foregroundStyle(.brown) } } #Preview { ContentView() }
Output

Example 2
In the following SwiftUI program, we apply different asymmetric transitions for both(true and false) state changes.
import SwiftUI struct ContentView: View { @State private var anime = false var body: some View { ZStack{ if anime{ RoundedRectangle(cornerRadius: 10) .fill(.red) .frame(width: 150, height: 100) // Here we apply asymmetric transition on the shape .transition(.asymmetric(insertion: .slide, removal: .push(from: .top))) }else{ RoundedRectangle(cornerRadius: 10) .fill(.yellow) .frame(width: 150, height: 100) // Here we apply asymmetric transition on the shape .transition(.asymmetric(insertion: .push(from: .top), removal: .slide)) } }.padding(30) Button("Click Me"){ withAnimation(.default){ anime.toggle() } }.font(.title).foregroundStyle(.brown) } } #Preview { ContentView() }
Output
