I am working on a slide in / out effect with opacity change that is achieved through following SwiftUI transition
VStack {
}
.transition(
.asymmetric(
insertion: .opacity
.combined(with: .offset(x: 50)),
removal: .opacity
.combined(with: .offset(x: -50))
)
)
In addition to opacity change and offset I would like to "blur in" the view on insertion and "blur out" the view in removal step. Unfortunately it looks like SwiftUI doesn’t offer .blur
transition to combine with here, so I wanted to ask if it is possible to add these kinds of custom transitions somehow and combine with them?
2
Answers
Then use it as follows:
💡 I’m using a simpler animation since it’s identical to the one you’ve provided
Method 1: Apply Modifier To A Conditional View
Wrap the conditional view in a group and apply the blur based on the conditions like:
Demo
Method 2: Custom Transition
You can create a custom transition using a custom
AnimatableModifier
.@Baffo rasta has mentioned this method before I have time to complete my answer and should have the credit, but here is mine which is some sort of refactored version of his:
Usage: