Animating UINavigationBarAppearance during scroll iOS 13

Viewed 308

I am trying to animate the new navigation bar appearance iOS 13 standard in one of my view controllers, specifically the backgroundEffect property. My goal is to have it appear normal and when the user scrolls down, the blur effect animates in.

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    let offset = scrollView.adjustedContentInset.top + scrollView.contentOffset.y
    if offset > 10  {
        let appearance = UINavigationBarAppearance()
        appearance.backgroundColor = .clear
        appearance.backgroundEffect = UIBlurEffect(style: .dark)
        appearance.shadowColor = .clear
        navigationItem.standardAppearance = appearance
    } else {
        let appearance = UINavigationBarAppearance()
        appearance.backgroundColor = .clear
        appearance.backgroundEffect = nil
        appearance.shadowColor = .clear
        navigationItem.standardAppearance = appearance
    }
}

It seems like I have to reset the entire navigation appearance instead of just setting the backgroundEffect. I have tried wrapping the appearance in a UIView.animate(), but it doesn't seem to work with that.

0 Answers
Related