QuaRang1225 / swiftui-photos

0 stars 0 forks source link

스크롤 애니메이션 렉 #8

Closed QuaRang1225 closed 2 months ago

QuaRang1225 commented 2 months ago

6 - 해당잇슈를 구현하다 생긴 문제

QuaRang1225 commented 2 months ago

현재 사용 중인 코드

GeometryReader{ proxy in
                    let minY = proxy.frame(in: .global).minY
                    Color.clear
                        .onChange(of: minY) { value in
                                if value < mainOffsetY{
                                    DispatchQueue.main.async{
                                        withAnimation {
                                            show = false
                                        }
                                    }

                                }
                                if value > mainOffsetY{
                                    DispatchQueue.main.async{
                                        withAnimation {
                                            show = true
                                        }
                                    }
                                }
                        }
                }.frame(height: 1)
QuaRang1225 commented 2 months ago

해결

GeometryReader{ proxy in
                    let minY = proxy.frame(in: .global).minY
                    Color.clear
                        .onChange(of: minY) { value in
                                if abs(value - lastminY) > 10 {    //임계값 10으로 설정
                                    lastminY = value
                                    withAnimation {
                                        if lastminY < mainOffsetY {
                                            show = false
                                        } else if lastminY > mainOffsetY {
                                            show = true
                                        }
                                    }
                                }
                        }
                }.frame(height: 1)