NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

How to detect the Reduce Motion accessibility setting

Paul Hudson    @twostraws   

Updated for Xcode 14.2

Many users are sensitive to animations, particularly those are large or complex. As a result, iOS has a built-in accessibility setting called Reduce Motion, which apps can read and respond to as appropriate.

In SwiftUI, this setting is exposed to us as an environment Boolean, so you should start by adding a property for it to your views:

@Environment(\.accessibilityReduceMotion) var reduceMotion

Now it’s down to you to decide what “reduce motion” means – should you remove your animations, or just change them to be less strong? Should you keep some important animations and just remove the ones that are for visual appeal?

For example, if you wanted a bouncy spring animation for most users, but no animation at all for users who want reduced motion, you might use an animation modifier like this one:

.animation(reduceMotion ? nil : .spring(response: 1, dampingFraction: 0.1), value: someValue) 

Here’s a complete example you can try:

struct ContentView: View {
    @Environment(\.accessibilityReduceMotion) var reduceMotion
    @State private var scale = 1.0

    var body: some View {
        VStack {

                .frame(width: 20, height: 20)
                .animation(reduceMotion ? nil : .spring(response: 1, dampingFraction: 0.1), value: scale)


            Button("Increase Scale") {
                scale *= 1.5

That creates a small circle, scaling it up with a spring animation every time the button is pressed. But if the user enables Reduce Motion, the animation is removed entirely – it uses nil for the animation() modifier.

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Similar solutions…

Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Average rating: 5.0/5

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.