在 SwiftUI 中滑动列表时隐藏导航栏 [英] Hide navigation bar on swipe of a list in SwiftUI

查看:59
本文介绍了在 SwiftUI 中滑动列表时隐藏导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 SwiftUI 中向上滑动时隐藏导航栏并在向下滑动时显示(例如在 facebook 上)?在 UKit 中有 navigationBar.hideBarsOnSwipe,但我似乎在 SwiftUI 中找不到这样的功能.我是不是遗漏了什么,还是在 swiftUI 中滑动时确实没有隐藏?

提前致谢!!

解决方案

到目前为止,SwiftUI 中没有原生 API(1.0 和 2.0).因此,这是一个基于

struct TestHideOnSwipe:查看{var主体:一些视图{导航视图{List(0..<100) { i in文本(项目\(i)")}.background(NavigationConfigurator { navigationConfigurator innavigationConfigurator.hidesBarsOnSwipe = true//<<这里 !!}).navigationBarTitle(Text(Demo"), displayMode: .inline)}}}

How to to hide the navigation bar when swiping up and to show when swiping down (like on facebook for example) in SwiftUI? In UKit there is navigationBar.hideBarsOnSwipe, but I do cannot seem to find such functionality in SwiftUI. Am I missing something, or there is indeed no hide on swipe in swiftUI?

Thanks in advance!!

解决方案

No native API in SwiftUI so far (both 1.0 & 2.0). So here is a possible working solution based on NavigationConfigurator provided in this answer

Tested with Xcode 12 / iOS 14

struct TestHideOnSwipe: View {

    var body: some View {
        NavigationView {
            List(0..<100) { i in
                Text("Item \(i)")
            }
            .background(NavigationConfigurator { navigationConfigurator in
                navigationConfigurator.hidesBarsOnSwipe = true     // << here !!
            })
            .navigationBarTitle(Text("Demo"), displayMode: .inline)
        }
    }
}

这篇关于在 SwiftUI 中滑动列表时隐藏导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆