반응형

 

Hacking with Swift 사이트의 강좌 번역본입니다.

 

[원문 : https://www.hackingwithswift.com/quick-start/swiftui/how-to-detect-the-reduce-motion-accessibility-setting]

 

How to detect the Reduce Motion accessibility setting

 

많은 사용자들은 애니메이션에 민감하며, 특히 더 크거나 복잡한 경우에 그렇습니다. 결과적으로, iOS는 Reduce Motion 이라는 접근성(accessibility) 설정을 내장하고 있으며, 앱은 적절히 읽고 응답할 수 있습니다.

 

SwiftUI에서, 해당 설정은 environment Boolean으로 나타내므로, 뷰에 프로퍼티를 추가해서 시작해야 합니다.

@Environment(\.accessibilityReduceMotion) var reduceMotion

 

이제 동작 감소(reduce motion)가 무엇을 의미하는지는 여러분에게 달렸습니다 - 애니메이션을 제거하거나 덜 강하게 변경해야 하나요? 중요한 애니메이션은 유지해야 하고 시각적으로 흥미가 있는 것들을 제거해야 하나요?

 

예를들어, 대부분의 사용자들이 튀어오르는(bouncy) 스프링(spring) 애니메이션을 원하는 경우, 동작 감소(reduce motion)를 원하는 사용자들에게는 애니메이션이 없도록, 다음과 같이 애니메이션 modifier를 수정할 수 있습니다.

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

 

다음은 완전한 예제입니다.

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

    var body: some View {
        VStack {
            Spacer()

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

            Spacer()

            Button("Increase Scale") {
                self.scale *= 1.5
            }
        }
    }
}

 

그것은 작은 사각형을 만들고, 버튼을 누를때마다 스프링 애니메이션으로 확대 합니다. 하지만 Reduce Motion을 활성화한 사용자의 경우에, 애니메이션은 완전히 제거됩니다 - animation() modifier에 대해  nil을 사용합니다.

반응형
Posted by 까칠코더
,